Skip to content

Commit

Permalink
236319-Spr-2023
Browse files Browse the repository at this point in the history
  • Loading branch information
dhlorenz committed May 16, 2024
1 parent f684280 commit 8fb0789
Show file tree
Hide file tree
Showing 57 changed files with 2,813 additions and 1,002 deletions.
2 changes: 1 addition & 1 deletion HW/Homework1/q1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
{
Construct the new line and then print it.
}
end;
end
end.
10 changes: 10 additions & 0 deletions HW/Homework2/q1.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
val it = () : unit
val it = fn : 'a -> 'b -> ('a * 'b -> 'b) -> 'b
val it = fn : int * real -> (real -> string) -> bool
val it = fn : ('a -> 'b -> 'c) -> 'a -> 'b -> 'd -> 'c
val it = fn : 'a -> 'b -> int -> int -> int
val it = fn : ('a -> 'b) -> 'a -> ('b * 'b -> 'c) -> 'c
val it = fn : unit -> unit -> int
val it = fn : 'a -> 'a * 'a -> 'a
val it = fn : int * string * string -> int * string * string
-
9 changes: 9 additions & 0 deletions HW/Homework2/q1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
print "===TEST START===\n";
sig1;
sig2;
sig3;
sig4;
sig5;
sig6;
sig7;
sig8;
6 changes: 6 additions & 0 deletions HW/Homework2/q2.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
val it = () : unit
val it = fn : int -> int -> int
val test_1 = "Passed" : string
val it = fn : int * int -> int
val test_2 = "Passed" : string
-
5 changes: 5 additions & 0 deletions HW/Homework2/q2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
print "===TEST START===\n";
curry op*;
val test_1 = if 12 = it 3 4 then "Passed" else "Failed";
uncurry it;
val test_2 = if 12 = it (3,4) then "Passed" else "Failed";
4 changes: 4 additions & 0 deletions HW/Homework2/q3.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
val it = () : unit
val test_1 = "Passed" : string
val test_2 = "Passed" : string
-
3 changes: 3 additions & 0 deletions HW/Homework2/q3.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
print "===TEST START===\n";
val test_1 = if alive = is_alive (alive, empty, empty) (empty, alive, alive) (empty, empty, empty) then "Passed" else "Failed";
val test_2 = if empty = is_alive (alive, alive, alive) (empty, alive, empty) (alive, alive, alive) then "Passed" else "Failed";
1 change: 1 addition & 0 deletions HW/Homework3/hw3_q1_def.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fun toChar false = #" " | toChar true = #"*"
13 changes: 13 additions & 0 deletions HW/Homework3/hw3_q2_def.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
signature KERNEL1D_SIG = sig
type source
type target
val kernel : source -> source -> source -> target
val default : source -> source
end;

signature KERNEL2D_SIG = sig
type source
type target
val kernel : source * source * source -> source * source * source -> source * source * source -> target
val default : source -> source
end;
9 changes: 9 additions & 0 deletions HW/Homework3/q1.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
val it = () : unit
val test1 = "PASSED" : string
val test2 = "PASSED" : string
val test3 = "PASSED" : string
val test4 = "PASSED" : string
*
* *
val test5 = () : unit

6 changes: 6 additions & 0 deletions HW/Homework3/q1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
print "===TEST START===\n";
val test1 = if (mapState (fn true => 1 | false => 0) [[false, true, false], [true, false, true]]) = [[0, 1, 0], [1, 0, 1]] then "PASSED" else "FAILED";
val test2 = if (toString (explode "Hello world")) = "Hello world" then "PASSED" else "FAILED";
val test3 = if (frameToState [" * ", "* *"]) = [[false, true, false], [true, false, true]] then "PASSED" else "FAILED";
val test4 = if (stateToFrame [[false, true, false], [true, false, true]]) = [" * ", "* *"]then "PASSED" else "FAILED";
val test5 = printFrame [" * ", "* *"];
6 changes: 6 additions & 0 deletions HW/Homework3/q2.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
val it = () : unit
val test1 = "PASSED" : string
val test2 = "PASSED" : string
val test3 = "PASSED" : string
val test4 = "PASSED" : string

20 changes: 20 additions & 0 deletions HW/Homework3/q2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fun sum a b c = a + b + c;

structure SumKernel1D = Kernel1D(struct
type source = int
type target = int
val kernel = sum
fun default _ = 0
end);
structure SumKernel2D = Kernel2D(struct
type source = int
type target = int
fun kernel (x1, x2, x3) (y1, y2, y3) (z1, z2, z3) = 2 * x2 + y2 + 3 * z2
fun default _ = 0
end);

print "===TEST START===\n";
val test1 = if (SumKernel1D.runKernel [1, 2, 3, 4]) = [3, 6, 9, 7] then "PASSED" else "FAILED";
val test2 = if (zip [1, 2, 3] [4, 5, 6] [7, 8, 9]) = [(1, 4, 7), (2, 5, 8), (3, 6, 9)] then "PASSED" else "FAILED";
val test3 = if (fill false 3) = [false, false, false] then "PASSED" else "FAILED";
val test4 = if (SumKernel2D.runKernel [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) = [[7, 13, 7], [19, 31, 16], [31, 49, 25]] then "PASSED" else "FAILED";
69 changes: 69 additions & 0 deletions HW/Homework3/selfcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

testsurl="https://raw.githubusercontent.com/AdiHarif/236319-Spr-2023/master/HW/Homework3/"

tmpdir="selfcheck_tmp"
test_files=("q1" "q2")
required_files=("hw3_q1.sml" "hw3_q2.sml" "dry.pdf")

if [ -z "$1" ]; then
echo "Usage: ./"$( basename "$0" )" <your submission zip file>"
exit
fi

if [ ! -f "$1" ]; then
echo "Submission zip file not found!"
exit
fi

rm -rf "$tmpdir" &> /dev/null
if [ -d "$tmpdir" ]
then
echo "Cannot clear tmp directory. Please delete '$tmpdir' manually and try again"
exit
fi
mkdir "$tmpdir" &> /dev/null

yes | apt install zip &> /dev/null

unzip "$1" -d "$tmpdir" &> /dev/null
if [[ $? != 0 ]]; then
echo "Unable to unzip submission file!"
exit
fi

cd "$tmpdir"
for f in "${required_files[@]}"
do
if [ ! -f $f ]; then
echo "File $f not found!"
exit
fi
done

if [ $( ls | wc -l ) != ${#required_files[@]} ]; then
echo "There are too many files in the submission"
exit
fi

for test in "${test_files[@]}"
do
wget "$testsurl$test.in" "$testsurl$test.expected" "${testsurl}hw3_${test}_def.sml" &> /dev/null
if [ ! -f "$test.in" ] || [ ! -f "$test.expected" ] || [ ! -f "hw3_${test}_def.sml" ]; then
echo "Unable to download test $test!"
exit
fi
sml hw3_$test.sml < $test.in &> $test.rawout
sed '1,/===TEST START===/d' $test.rawout > $test.out
diff $test.out $test.expected
if [[ $? != 0 ]]; then
echo "Failed test $test!"
exit
fi
done

cd - &> /dev/null
rm -rf "$tmpdir"

echo "Ok to submit :)"
exit
51 changes: 51 additions & 0 deletions HW/Homework4/hw4_q1_def.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use "hw2_q3.sml";
use "hw3_q1.sml";
use "hw3_q2.sml";

local
fun toCell false = empty
| toCell true = alive;
in
fun is_alive_bool (x1, x2, x3) (y1, y2, y3) (z1, z2, z3) =
case (
is_alive
(toCell x1, toCell x2, toCell x3)
(toCell y1, toCell y2, toCell y3)
(toCell z1, toCell z2, toCell z3)) of empty => false | alive => true
end;

fun run f 0 _ = ()
| run f times delay = (f(); OS.Process.system ("sleep " ^ Real.toString delay); run f (times - 1) delay);

val start_frame = [
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" *** *** *** *** * *** ",
" * * * * ** * * ",
" *** *** *** *** * *** ",
" * * * * * * * ",
" *** *** *** *** *** *** ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "];
5 changes: 5 additions & 0 deletions HW/Homework4/hw4_q2_def.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
datatype 'a tree =
Nil
| Br of 'a * ('a tree) * ('a tree);

datatype ('a, 'b) union = type1 of 'a | type2 of 'b;
12 changes: 12 additions & 0 deletions HW/Homework4/hw4_q3_def.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
datatype 'a seq = Nil | Cons of 'a * (unit -> 'a seq);

fun counter () = let
val count = ref 0;
fun aux n () = Cons (n + 1, (
count := 1 + !count;
print ("exec: " ^ Int.toString (!count) ^ "\n");
aux (n + 1)
))
in
(Cons(0, aux 0))
end;
16 changes: 16 additions & 0 deletions HW/Homework4/q1.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
val it = () : unit
val test1 = "PASSED" : string
val game = fn : unit -> unit
***
* *
***
val it = () : unit
* *
* *
* *
val it = () : unit

** **

val it = () : unit

6 changes: 6 additions & 0 deletions HW/Homework4/q1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
print "===TEST START===\n";
val test1 = if (runCycle [" *** ", " * * ", " *** "]) = [" * * ","* *"," * * "] then "PASSED" else "FAILED";
val game = gameOfLife [" *** ", " * * ", " *** "];
game();
game();
game();
4 changes: 4 additions & 0 deletions HW/Homework4/q2.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
val it = () : unit
val it = [0,1,2] : int list
val it = Br (0,Br (2,Nil,Nil),Br (4,Nil,Nil)) : int tree

3 changes: 3 additions & 0 deletions HW/Homework4/q2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
print "===TEST START===\n";
flatten (Br(0, Br(1, Nil, Nil), Br(2, Nil, Nil)));
map (fn x => 2 * x) (Br(0, Br(1, Nil, Nil), Br(2, Nil, Nil)));
10 changes: 10 additions & 0 deletions HW/Homework4/q3.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
val it = () : unit
exec: 1
val it = () : unit
exec: 2
val it = () : unit
val it = () : unit
val it = () : unit
exec: 3
val it = () : unit
-
8 changes: 8 additions & 0 deletions HW/Homework4/q3.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
val s = ref (new (counter ()));

print "===TEST START===\n";
s := next (!s);
s := next (!s);
s := prev (!s);
s := next (!s);
s := next (!s);
85 changes: 85 additions & 0 deletions HW/Homework4/selfcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

hw2="https://raw.githubusercontent.com/AdiHarif/236319-Spr-2023/master/HW/Homework2/"
hw3="https://raw.githubusercontent.com/AdiHarif/236319-Spr-2023/master/HW/Homework3/"
hw4="https://raw.githubusercontent.com/AdiHarif/236319-Spr-2023/master/HW/Homework4/"

tmpdir="selfcheck_tmp"
test_files=("q1" "q2" "q3")
required_files=("hw4_q1.sml" "hw4_q2.sml" "hw4_q3.sml" "dry.pdf")

if [ -z "$2" ]; then
echo "Usage: ./"$( basename "$0" )" <your submission zip file> <directory with previous solutions>"
exit
fi

if [ ! -f "$1" ]; then
echo "Submission zip file not found!"
exit
fi

if [ ! -d "$2" ]; then
echo "Directory with previous solutions not found!"
exit
fi

rm -rf "$tmpdir" &> /dev/null
if [ -d "$tmpdir" ]
then
echo "Cannot clear tmp directory. Please delete '$tmpdir' manually and try again"
exit
fi
mkdir "$tmpdir" &> /dev/null

yes | apt install zip &> /dev/null

unzip "$1" -d "$tmpdir" &> /dev/null
if [[ $? != 0 ]]; then
echo "Unable to unzip submission file!"
exit
fi

cd "$tmpdir"
for f in "${required_files[@]}"
do
if [ ! -f $f ]; then
echo "File $f not found!"
exit
fi
done

if [ $( ls | wc -l ) != ${#required_files[@]} ]; then
echo "There are too many files in the submission"
exit
fi

cp ../$2/* . &> /dev/null

wget "${hw3}hw3_q1_def.sml" "${hw3}hw3_q2_def.sml" &> /dev/null
if [ ! -f "hw3_q1_def.sml" ] || [ ! -f "hw3_q2_def.sml" ]; then
echo "Unable to download def files from previous homeworks!"
exit
fi

for test in "${test_files[@]}"
do
wget "$hw4$test.in" "$hw4$test.expected" "${hw4}hw4_${test}_def.sml" &> /dev/null
sleep 3
if [ ! -f "$test.in" ] || [ ! -f "$test.expected" ] || [ ! -f "hw4_${test}_def.sml" ]; then
echo "Unable to download test $test!"
exit
fi
sml hw4_$test.sml < $test.in &> $test.rawout
sed '1,/===TEST START===/d' $test.rawout > $test.out
diff $test.out $test.expected
if [[ $? != 0 ]]; then
echo "Failed test $test!"
exit
fi
done

cd - &> /dev/null
rm -rf "$tmpdir"

echo "Ok to submit :)"
exit
Loading

0 comments on commit 8fb0789

Please sign in to comment.