Skip to content

Commit

Permalink
Split out tests into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-byrne committed Sep 20, 2024
1 parent 4be2977 commit a23cc13
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/tests-ica05/test_addLists.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

val testCasesAddLists = [
(addLists, ([1, 2, 3], [4, 5, 6]), [5, 7, 9]),
(addLists, ([1, 2], [4, 5, 6]), [5, 7]),
(addLists, ([1, 2, 3], []), []),
(addLists, ([], [4, 5, 6]), []),
(addLists, ([], []), []),
(addLists, ([1, 2, 3], [4, 5, 6, 7]), [5, 7, 9]),
(addLists, ([1, 2, 3, 4, 5], [4, 5, 6, 0, 0]), [5, 7, 9, 4, 5])
];
runTestCasesIntListIntList(testCasesAddLists);
14 changes: 14 additions & 0 deletions tests/tests-ica05/test_andList.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

val testCasesAndList = [
(andList, [true, true, true], true),
(andList, [true, false, true], false),
(andList, [false, false, false], false),
(andList, [], true), (* Empty list case *)
(andList, [true], true),
(andList, [false], false)
];
runTestCasesBoolListBool(testCasesAndList);
27 changes: 27 additions & 0 deletions tests/tests-ica05/test_combineLists.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

fun mockAdd(x, y) = x + y;
fun mockModulus(x, y) = x mod y;
fun mockDiv(x, y) = x div y;
fun doNothing(x, y) = x;

val testCasesCombineLists = [
(combineLists, [1, 2, 3], [4, 5, 6], mockAdd, [5, 7, 9]),
(combineLists, [1, 2], [4, 5, 6], mockAdd, [5, 7]),
(combineLists, [], [4, 5, 6], mockModulus, []),
(combineLists, [], [], mockModulus, []),
(combineLists, [1, 2, 3], [4, 5, 6], mockDiv, [0, 0, 0]),
(combineLists, [1, 2], [4, 5, 6], mockDiv, [0, 0]),
(combineLists, [8, 8, 3], [4], mockDiv, [2]),
(combineLists, [4], [4, 5, 6], mockDiv, [1]),
(combineLists, [], [], mockDiv, []),
(combineLists, [1, 2, 3], [4, 5, 6], doNothing, [1, 2, 3]),
(combineLists, [1, 2], [4, 5, 6], doNothing, [1, 2]),
(combineLists, [1, 2, 3], [], doNothing, []),
(combineLists, [], [4, 5, 6], doNothing, []),
(combineLists, [], [], doNothing, [])
];
runTestCasesIntListIntListOperatorToIntList(testCasesCombineLists);
17 changes: 17 additions & 0 deletions tests/tests-ica05/test_countZeros.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

val testCasesCountZeros = [
(countZeros, [0, 1, 0, 1, 0], 3),
(countZeros, [1, 1, 1, 1, 1], 0),
(countZeros, [0, 0, 0, 0, 0], 5),
(countZeros, [], 0),
(countZeros, [0], 1),
(countZeros, [1], 0),
(countZeros, [0, 0, 0, 1, 0], 4),
(countZeros, [1, 0, 1, 0, 1], 2),
(countZeros, [0, 0, 1, 0, 0, 0], 5)
];
runTestCasesIntListInt(testCasesCountZeros);
18 changes: 18 additions & 0 deletions tests/tests-ica05/test_factorial.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

val testCasesFactorial = [
(factorial, 0, 1), (* 0! = 1 *)
(factorial, 1, 1), (* 1! = 1 *)
(factorial, 2, 2), (* 2! = 2 *)
(factorial, 3, 6), (* 3! = 6 *)
(factorial, 4, 24), (* 4! = 24 *)
(factorial, 5, 120), (* 5! = 120 *)
(factorial, 6, 720), (* 6! = 720 *)
(factorial, 7, 5040), (* 7! = 5040 *)
(factorial, 8, 40320), (* 8! = 40320 *)
(factorial, 10, 3628800) (* 10! = 3628800 *)
];
runTestCasesIntInt(testCasesFactorial);
20 changes: 20 additions & 0 deletions tests/tests-ica05/test_fib.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

val testCasesFib = [
(* a_n = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55} *)
(fib, 0, 0),
(fib, 1, 1),
(fib, 2, 1),
(fib, 3, 2),
(fib, 4, 3),
(fib, 5, 5),
(fib, 6, 8),
(fib, 7, 13),
(fib, 8, 21),
(fib, 9, 34),
(fib, 10, 55)
];
runTestCasesIntInt(testCasesFib);
17 changes: 17 additions & 0 deletions tests/tests-ica05/test_log2.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

val testCasesLog2 = [
(log2, 1, 0), (* 2^0 = 1 *)
(log2, 2, 1), (* 2^1 = 2 *)
(log2, 4, 2), (* 2^2 = 4 *)
(log2, 8, 3), (* 2^3 = 8 *)
(log2, 16, 4), (* 2^4 = 16 *)
(log2, 32, 5), (* 2^5 = 32 *)
(log2, 64, 6), (* 2^6 = 64 *)
(log2, 128, 7), (* 2^7 = 128 *)
(log2, 256, 8) (* 2^8 = 256 *)
];
runTestCasesIntInt(testCasesLog2);
18 changes: 18 additions & 0 deletions tests/tests-ica05/test_orList.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

val testCasesOrList = [
(orList, [true, true, true], true),
(orList, [true, false, true], true),
(orList, [false, false, false], false),
(orList, [true, true, false], true),
(orList, [false, false, true], true),
(orList, [false, false, false, false], false),
(orList, [false, true, false, true], true),
(orList, [], false), (* Empty list case *)
(orList, [false], false), (* Single false element *)
(orList, [true], true) (* Single true element *)
];
runTestCasesBoolListBool(testCasesOrList);
16 changes: 16 additions & 0 deletions tests/tests-ica05/test_removeZeros.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

val testCasesRemoveZeros = [
(removeZeros, [0, 1, 0, 2], [1, 2]),
(removeZeros, [0, 0, 0], []),
(removeZeros, [1, 2, 3], [1, 2, 3]),
(removeZeros, [], []),
(removeZeros, [0], []),
(removeZeros, [1], [1]),
(removeZeros, [0, 0, 0, 1, 0], [1]),
(removeZeros, [1, 0, 1, 0, 1], [1, 1, 1])
];
runTestCasesIntListIntList(testCasesRemoveZeros);
16 changes: 16 additions & 0 deletions tests/tests-ica05/test_reverseList.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(* ICA 5 tests *)

use "src/ica05/ica5.sml";
use "tests/utils.sml";

val testCasesReverseList = [
(reverseList, [1, 2, 3], [3, 2, 1]),
(reverseList, [1], [1]),
(reverseList, [], []),
(reverseList, [4, 5, 6, 7], [7, 6, 5, 4]),
(reverseList, [1, 2, 3, 4, 5], [5, 4, 3, 2, 1]),
(reverseList, [1, 2, 3, 4, 5, 6], [6, 5, 4, 3, 2, 1]),
(reverseList, [1, 0, 0, 1, 0], [0, 1, 0, 0, 1]),
(reverseList, [0, 0, 0], [0, 0, 0])
];
runTestCasesIntListIntList(testCasesReverseList);

0 comments on commit a23cc13

Please sign in to comment.