From 82e73e6c8e7a7613db98f5b229ab7665b9940b00 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Mon, 28 May 2018 13:42:33 -0400 Subject: [PATCH] Add (incomplete) test case for queens.tig --- tiger/src/exe/tiger_tests.ml | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tiger/src/exe/tiger_tests.ml b/tiger/src/exe/tiger_tests.ml index 2def01a..761d43e 100644 --- a/tiger/src/exe/tiger_tests.ml +++ b/tiger/src/exe/tiger_tests.ml @@ -147,12 +147,62 @@ let test_09 = (* TODO: Type error test case *) (name, code, tokens) +let test_queens = + let code = + " \n\ + /* A program to solve the 8-queens problem */ \n\ + \n\ + let \n\ + var N := 8 \n\ + \n\ + type intArray = array of int \n\ + \n\ + var row := intArray [ N ] of 0 \n\ + var col := intArray [ N ] of 0 \n\ + var diag1 := intArray [N+N-1] of 0 \n\ + var diag2 := intArray [N+N-1] of 0 \n\ + \n\ + function printboard() = ( \n\ + for i := 0 to N-1 do ( \n\ + for j := 0 to N-1 do print(if col[i]=j then \" O\" else \" .\"); \n\ + print(\"\n\") \n\ + ); \n\ + print(\"\n\") \n\ + ) \n\ + \n\ + function try(c:int) = ( \n\ + /* for i:= 0 to c do print(\".\"); print(\"\n\"); flush();*/ \n\ + if c=N \n\ + then printboard() \n\ + else \n\ + for r := 0 to N-1 \n\ + do \n\ + if row[r]=0 & diag1[r+c]=0 & diag2[r+7-c]=0 \n\ + then ( \n\ + row[r] := 1; \n\ + diag1[r+c] := 1; \n\ + diag2[r+7-c] := 1; \n\ + col[c] := r; \n\ + try(c+1); \n\ + row[r] := 0; \n\ + diag1[r+c] := 0; \n\ + diag2[r+7-c] := 0 \n\ + ) \n\ + ) \n\ + in \n\ + try(0) \n\ + end \n\ + " + in + (code, code, []) + let tests = [ test_01 ; test_02 ; test_03 ; test_04 ; test_09 + ; test_queens ] let () = -- 2.20.1