Anonymous avatar Anonymous committed af8318c

Implemented the free function

Comments (0)

Files changed (3)

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

 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();

nurikabe-solver/verdict_mat.c

     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;
+}
+

nurikabe-solver/verdict_mat.h

         );
 
 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 */
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.