Skip to content

Commit

Permalink
Fix test container configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-byrne committed Sep 20, 2024
1 parent 1d69eed commit 836da73
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/run-sml-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jobs:
sudo apt-get update
sudo apt-get install smlnj # Install SML/NJ
sudo apt-get install smlsharp # Install SML#
sudo apt-get install llvm-14 # Install LLVM 14
sudo apt-get install libmyth # Install mythril
# Add the path to the libmyth.so file to the LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
# Create a symbolic link to the libmyth.so file
sudo ln -s /usr/lib/x86_64-linux-gnu/libmyth.so.0 /usr/lib/x86_64-linux-gnu/libmyth.so
- name: Run SML tests
run: |
Expand Down
10 changes: 10 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/bin/bash

sudo apt update
sudo apt-get update
sudo apt-get install -y software-properties-common

sudo apt install smlsharp
sudo apt-get install llvm-14
sudo apt-get install libmyth

echo 'export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
sudo ln -s /usr/lib/x86_64-linux-gnu/libmyth.so.0 /usr/lib/x86_64-linux-gnu/libmyth.so

chmod +x ./start-wiki
chmod +x ./test
Expand Down
5 changes: 4 additions & 1 deletion test
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

#sudo find / -name "libmyth.*"
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH

# Define the path to the tests folder
TESTS_DIR="./tests"

Expand All @@ -15,5 +18,5 @@ fi
# Load each test file in the SML interpreter
for TEST_FILE in $TEST_FILES; do
echo "Running tests in: $TEST_FILE"
sml < "$TEST_FILE"
smlsharp < "$TEST_FILE"
done
99 changes: 99 additions & 0 deletions tests/temp.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use "src/ica05/ica5.sml" (* Test runner called from root of project *)

(* Tests for log2 *)
val test_log2 = SU.suite "Log2 Tests" [
SU.test "log2(1)" (fn () => SU.assertEqual (log2 1, 0)),
SU.test "log2(2)" (fn () => SU.assertEqual (log2 2, 1)),
SU.test "log2(4)" (fn () => SU.assertEqual (log2 4, 2)),
SU.test "log2(8)" (fn () => SU.assertEqual (log2 8, 3)),
SU.test "log2(16)" (fn () => SU.assertEqual (log2 16, 4))
]

(* Tests for factorial *)
val test_factorial = SU.suite "Factorial Tests" [
SU.test "factorial(0)" (fn () => SU.assertEqual (factorial 0, 1)),
SU.test "factorial(1)" (fn () => SU.assertEqual (factorial 1, 1)),
SU.test "factorial(2)" (fn () => SU.assertEqual (factorial 2, 2)),
SU.test "factorial(3)" (fn () => SU.assertEqual (factorial 3, 6)),
SU.test "factorial(4)" (fn () => SU.assertEqual (factorial 4, 24)),
SU.test "factorial(5)" (fn () => SU.assertEqual (factorial 5, 120))
]

(* Tests for fib *)
val test_fib = SU.suite "Fibonacci Tests" [
SU.test "fib(0)" (fn () => SU.assertEqual (fib 0, 0)),
SU.test "fib(1)" (fn () => SU.assertEqual (fib 1, 1)),
SU.test "fib(2)" (fn () => SU.assertEqual (fib 2, 1)),
SU.test "fib(3)" (fn () => SU.assertEqual (fib 3, 2)),
SU.test "fib(4)" (fn () => SU.assertEqual (fib 4, 3)),
SU.test "fib(5)" (fn () => SU.assertEqual (fib 5, 5)),
SU.test "fib(6)" (fn () => SU.assertEqual (fib 6, 8)),
SU.test "fib(7)" (fn () => SU.assertEqual (fib 7, 13))
]

(* Tests for countZeros *)
val test_countZeros = SU.suite "Count Zeros Tests" [
SU.test "countZeros([0,1,0,1,0])" (fn () => SU.assertEqual (countZeros [0,1,0,1,0], 3)),
SU.test "countZeros([1,1,1,1,1])" (fn () => SU.assertEqual (countZeros [1,1,1,1,1], 0)),
SU.test "countZeros([0,0,0,0,0])" (fn () => SU.assertEqual (countZeros [0,0,0,0,0], 5)),
SU.test "countZeros([])" (fn () => SU.assertEqual (countZeros [], 0)),
SU.test "countZeros([0])" (fn () => SU.assertEqual (countZeros [0], 1)),
SU.test "countZeros([1])" (fn () => SU.assertEqual (countZeros [1], 0))
]

(* Tests for orList *)
val test_orList = SU.suite "orList Tests" [
SU.test "orList([true, true, true])" (fn () => SU.assertEqual (orList [true, true, true], true)),
SU.test "orList([true, false, true])" (fn () => SU.assertEqual (orList [true, false, true], true)),
SU.test "orList([false, false, false])" (fn () => SU.assertEqual (orList [false, false, false], false)),
SU.test "orList([true, true, false])" (fn () => SU.assertEqual (orList [true, true, false], true)),
SU.test "orList([false, false, true])" (fn () => SU.assertEqual (orList [false, false, true], true))
]

(* Tests for andList *)
val test_andList = SU.suite "andList Tests" [
SU.test "andList([true, true, true])" (fn () => SU.assertEqual (andList [true, true, true], true)),
SU.test "andList([true, false, true])" (fn () => SU.assertEqual (andList [true, false, true], false)),
SU.test "andList([false, false, false])" (fn () => SU.assertEqual (andList [false, false, false], false)),
SU.test "andList([true, true, false])" (fn () => SU.assertEqual (andList [true, true, false], false)),
SU.test "andList([true, true, true])" (fn () => SU.assertEqual (andList [true, true, true], true))
]

(* Tests for addLists *)
val test_addLists = SU.suite "addLists Tests" [
SU.test "addLists([1,2,3], [4,5,6])" (fn () => SU.assertEqual (addLists([1,2,3], [4,5,6]), [5,7,9])),
SU.test "addLists([1,2], [3,4,5])" (fn () => SU.assertEqual (addLists([1,2], [3,4,5]), [4,6,5])),
SU.test "addLists([1,2,3], [4])" (fn () => SU.assertEqual (addLists([1,2,3], [4]), [5,2,3]))
]

(* Tests for reverseList *)
val test_reverseList = SU.suite "reverseList Tests" [
SU.test "reverseList([1,2,3])" (fn () => SU.assertEqual (reverseList [1,2,3], [3,2,1])),
SU.test "reverseList([])" (fn () => SU.assertEqual (reverseList [], [])),
SU.test "reverseList([1])" (fn () => SU.assertEqual (reverseList [1], [1]))
]

(* Tests for removeZeros *)
val test_removeZeros = SU.suite "removeZeros Tests" [
SU.test "removeZeros([0,1,0,2,0,3])" (fn () => SU.assertEqual (removeZeros [0,1,0,2,0,3], [1,2,3])),
SU.test "removeZeros([1,2,3])" (fn () => SU.assertEqual (removeZeros [1,2,3], [1,2,3])),
SU.test "removeZeros([0,0,0])" (fn () => SU.assertEqual (removeZeros [0,0,0], []))
]

(* Tests for combineLists *)
val test_combineLists = SU.suite "combineLists Tests" [
SU.test "combineLists([1,2,3], [4,5,6], fn x => x)" (fn () => SU.assertEqual (combineLists([1,2,3], [4,5,6], fn x => x), [5,7,9])),
SU.test "combineLists([1,2], [3,4], fn x => x * 2)" (fn () => SU.assertEqual (combineLists([1,2], [3,4], fn x => x * 2), [8,12]))
]

(* Run all tests *)
val _ = SU.run test_log2
val _ = SU.run test_factorial
val _ = SU.run test_fib
val _ = SU.run test_countZeros
val _ = SU.run test_orList
val _ = SU.run test_andList
val _ = SU.run test_addLists
val _ = SU.run test_reverseList
val _ = SU.run test_removeZeros
val _ = SU.run test_combineLists
10 changes: 7 additions & 3 deletions tests/test_ica5.sml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
structure SU = SMLUnit
open SU
use "../src/ica05/ica5.sml"
structure Test = SMLUnit.Test
structure Assert = SMLUnit.Assert
val _ = Assert.assertTrue (true)
(* open SU *)
(* val _ = SU.assertEqual (1, 1) *)

use "src/ica05/ica5.sml" (* Test runner called from root of project *)

(* Tests for log2 *)
val test_log2 = SU.suite "Log2 Tests" [
Expand Down

0 comments on commit 836da73

Please sign in to comment.