1. Shlomi Fish
  2. nurikabe

Commits

shl...@b384bcd7-cfd4-0310-aca0-d78b80f7b91b  committed af8318c

Implemented the free function

  • Participants
  • Parent commits 32e480b
  • Branches default

Comments (0)

Files changed (3)

File nurikabe-solver/t/verdict-matrix-tests.py.t

View file
  • Ignore whitespace
 from TAP.Simple import *
 from ctypes import *
 
-plan(2)
+plan(3)
 
 NK_SOLVE_ERROR__SUCCESS = 0
 NK_SOLVE_ERRRO__ALLOC_FAILED = 1
 nk_solve = CDLL("./libnk-solve.so")
 
 verdict_mat_create = nk_solve.nk_solve_verdict_matrix_create
+verdict_mat_free = nk_solve.nk_solve_verdict_matrix_free
 
-matrix = c_void_p()
-ret = verdict_mat_create(5, 10, byref(matrix))
+class Mat:
+    def __init__(self):
+        self.matrix = c_void_p()
+    
+    def create(self, y, x):
+        return nk_solve.nk_solve_verdict_matrix_create(
+                c_int(y), c_int(x), byref(self.matrix)
+                )
 
+    def free(self):
+        return nk_solve.nk_solve_verdict_matrix_free(self.matrix)
 
-# TEST
-eq_ok (ret, NK_SOLVE_ERROR__SUCCESS, 
-        "nk_solve_verdict_matrix_create correct error value"
-        )
+def test1():
+    m = Mat()
+    # TEST
+    eq_ok (
+            m.create(10, 5), 
+            NK_SOLVE_ERROR__SUCCESS, 
+            "nk_solve_verdict_matrix_create correct error value"
+            )
 
-# TEST
-ok(matrix, "matrix is allocated")
+    # TEST
+    ok (m.matrix, "matrix is allocated")
 
+    # TEST
+    eq_ok (
+            m.free(),
+            NK_SOLVE_ERROR__SUCCESS,
+            "nk_solve_verdict_matrix_free was successful"
+            )
+
+test1();

File nurikabe-solver/verdict_mat.c

View file
  • Ignore whitespace
     return NK_SOLVE_ERROR__SUCCESS;
 }
 
+NK_SOLVE_ERROR_CODE
+nk_solve_verdict_matrix_free(nk_solve_verdict_matrix_t * matrix)
+{
+    g_free(matrix->buf);
+    matrix->buf = 0;
+    g_free(matrix);
+
+    return NK_SOLVE_ERROR__SUCCESS;
+}
+

File nurikabe-solver/verdict_mat.h

View file
  • Ignore whitespace
         );
 
 extern NK_SOLVE_ERROR_CODE
+nk_solve_verdict_matrix_free(nk_solve_verdict_matrix_t * matrix);
+
+extern NK_SOLVE_ERROR_CODE
 nk_solve_verdict_matrix_set(
     nk_solve_verdict_matrix_t * board,
     gint y,
     nk_solve_verdict_t * value
     );
 
-extern NK_SOLVE_ERROR_CODE
-nk_solve_verdict_matrix_free(nk_solve_verdict_matrix_t * matrix);
 
 #endif /* #ifndef NK_SOLVE__VERDICT_MAT_H */