Commits

Anonymous committed b3da605

Implemented nk_solve_verdict_matrix_create.

Comments (0)

Files changed (3)

nurikabe-solver/cell_mat.c

 #include "cell_mat.h"
 
+NK_SOLVE_ERROR_CODE
+nk_solve_verdict_matrix_create(
+        gint height,
+        gint width,
+        nk_solve_verdict_matrix_t * * result
+        )
+{
+    nk_solve_verdict_matrix_t * ret;
+
+    *result = NULL;
+
+    ret = g_new(nk_solve_verdict_matrix_t, 1);
+
+    if (! ret)
+    {
+        return NK_SOLVE_ERROR__ALLOC_FAILED;
+    }
+
+    ret->width = width;
+    ret->height = height;
+
+    ret->buf = g_malloc0((width*height)>>2);
+    if (! ret->buf)
+    {
+        g_free(ret);
+
+        return NK_SOLVE_ERROR__ALLOC_FAILED;
+    }
+
+    *result = ret;
+
+    return NK_SOLVE_ERROR__SUCCESS;
+}
+

nurikabe-solver/cell_mat.h

 
 enum NK_SOLVE_VERDICT
 {
-    NK_SOLVE_VERDICT__UNKNOWN,
-    NK_SOLVE_VERDICT__WHITE,
-    NK_SOLVE_VERDICT__BLACK,
+    NK_SOLVE_VERDICT__UNKNOWN = 0,
+    NK_SOLVE_VERDICT__WHITE = 1,
+    NK_SOLVE_VERDICT__BLACK = 2,
 };
 
 typedef enum 
     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 */
 

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

+#!/usr/bin/env python
+from TAP.Simple import *
+from ctypes import *
+
+plan(2)
+
+NK_SOLVE_ERROR__SUCCESS = 0
+NK_SOLVE_ERRRO__ALLOC_FAILED = 1
+NK_SOLVE_ERROR__X_OUT_OF_BOUNDS = 2
+NK_SOLVE_ERROR__Y_OUT_OF_BOUNDS = 3
+
+nk_solve = CDLL("./libnk-solve.so")
+
+verdict_mat_create = nk_solve.nk_solve_verdict_matrix_create
+
+matrix = c_void_p()
+ret = verdict_mat_create(5, 10, byref(matrix))
+
+
+# TEST
+eq_ok (ret, NK_SOLVE_ERROR__SUCCESS, 
+        "nk_solve_verdict_matrix_create correct error value"
+        )
+
+# TEST
+ok(matrix, "matrix is allocated")
+