Permalink
Browse files

Implemented and lightly tested TestSet and SolnSet, began work on bas…

…is.sml, the main method suite
  • Loading branch information...
jwelch01 committed Nov 6, 2011
1 parent b0e5826 commit 4bf79f946ae9f7f90f591b6fd54e04af851e5dc2
@@ -0,0 +1,46 @@
+-given nr test 1, jkenne05 passed
+-given nr test 1, hlin02 passed
+-given nr test 1, esalow01 failed -- We created a LargeInteger with value zero, but your code produced no output.
+-given nr test 1, bkolta01 passed
+-given nr test 1, gong01 passed
+-given nr test 1, nr passed
+-given nr test 1, bjorda02 passed
+-given nr test 1, kmcneely passed
+-given nr test 1, jtan03 failed -- We created a LargeInteger with value zero, but your code computed "List( 0 )".
+-given nr test 1, rmonde01 passed
+-given nr test 1, ariley03 failed -- We created a LargeInteger with value zero, but your code produced no output.
+-given nr test 1, agallant passed
+-given nr test 1, jpearl05 passed
+-given nr test 1, bsumne01 passed
+-given nr test 1, tsoule01 passed
+-given nr test 1, hnasar01 passed
+-given nr test 1, mrusse03 passed
+-given nr test 1, adreyf01 passed
+-given nr test 1, dwhitn01 passed
+-given nr test 1, sgardn04 passed
+-given nr test 1, jaltre01 passed
+-given nr test 1, nbugas01 passed
+-given nr test 1, mleise01 passed
+-given nr test 2, jkenne05 passed
+-given nr test 2, hlin02 passed
+-given nr test 2, esalow01 failed -- We tried to compute LargeInteger 0 using only 1, 0, and +, but your code produced no output.
+-given nr test 2, bkolta01 passed
+-given nr test 2, gong01 passed
+-given nr test 2, nr passed
+-given nr test 2, bjorda02 passed
+-given nr test 2, kmcneely passed
+-given nr test 2, jtan03 failed -- We tried to compute LargeInteger 0 using only 1, 0, and +, but your code computed "List( 0 )".
+-given nr test 2, rmonde01 passed
+-given nr test 2, ariley03 failed -- We tried to compute LargeInteger 0 using only 1, 0, and +, but your code produced no output.
+-given nr test 2, agallant passed
+-given nr test 2, jpearl05 passed
+-given nr test 2, bsumne01 passed
+-given nr test 2, tsoule01 passed
+-given nr test 2, hnasar01 passed
+-given nr test 2, mrusse03 passed
+-given nr test 2, adreyf01 passed
+-given nr test 2, dwhitn01 passed
+-given nr test 2, sgardn04 passed
+-given nr test 2, jaltre01 passed
+-given nr test 2, nbugas01 passed
+-given nr test 2, mleise01 passed

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,47 @@
+structure map = TernaryStringMap(TernaryKeyChar)
+structure listMap = ListMapFn(map)
+structure m = EmbedMap(structure L1 = map
+ structure L2 = listMap)
+structure g = BasicGraph
+structure tSet = TestSet(Outcome)
+structure sSet = SolnSet(Outcome)
+
+
+(* Build a map from tests to student * outcome lists from input file *)
+fun readToMap fd =
+ let fun build fd map =
+ case TextIO.inputLine fd
+ of NONE => map
+ | SOME line => let val {num, outcome, solnid, testid} =
+ OutcomeReader.outcome line
+ in build fd
+ (m.add ((explode testid, explode (Int.toString num)),
+ (solnid, outcome),
+ map))
+ end
+ in build fd m.empty
+ end
+
+
+(* Turn map into a TestSet *)
+fun makeTestSet map = m.mapFold
+ (fn ((k1,k2), resultList, set) => tSet.add ((implode k1, implode k2, resultList), set))
+ tSet.empty map
+
+(* Partition TestSet *)
+fun eqResult ((id, num, ol), (id2, num2, ol2)) =
+ (ListPair.foldrEq (fn ((_,out1), (_,out2), flag) =>
+ Outcome.eq (out1, out2) andalso flag) true (ol, ol2)
+ handle UnequalLengths => false)
+val partitionTests = tSet.partition eqResult
+
+(* Make map from solns -> test * outcome list using a representative from each
+eq class *)
+
+(* Turn map into SolnSet *)
+
+(* Partition SolnSet *)
+
+(* Find subset relations *)
+
+(* produce graph *)
@@ -8,7 +8,8 @@ group is $/basis.cm
graphsig.sml
setsig.sml
- set.sml
+ testset.sml
+ solnset.sml
ternarykeychar.sml
ternarystringmap.sml
@@ -38,7 +38,7 @@ and insert _ x [] = [x]
fun cmpResultName ((x, _), (y, _)) = String.compare (x, y)
-val cmpResult = fn ((x,y), (x2,y2)) => x = x2 andalso cmpOutcomesEq (y,y2)
+val cmpResult = fn ((x,y), (x2,y2)) => x = x2 andalso Outcome.eq (y,y2)
fun removeDuplicates ((k1,k2), result, resultList) =
let fun findEq (_, r) = ListPair.allEq cmpResult
@@ -0,0 +1,96 @@
+functor SolnSet (Outcome : OUTCOME) : SET = struct
+ type elem = (string * (string * int * Outcome.outcome) list)
+ type set = elem list
+
+ exception NotFound
+ exception NotImplemented
+
+(* Helper functions *)
+
+fun insertion_sort _ [] = []
+ | insertion_sort cmp (x::xs) = insert cmp x (insertion_sort cmp xs)
+and insert _ x [] = [x]
+ | insert cmp x (l as y::ys) =
+ case cmp (x, y) of GREATER => y :: insert cmp x ys
+ | _ => x :: l
+
+fun cmpTests ((id1, num1), (id2, num2)) =
+ case String.compare (id1, id2)
+ of EQUAL => Int.compare (num1, num2)
+ | x => x
+
+
+(* Real functions *)
+
+ val empty = []
+ fun add (x, s) = x::s
+
+ fun representative [] = NONE
+ | representative (x::_) = SOME x
+ fun rep x = case representative x of SOME y => y
+ | NONE => raise NotFound
+
+ fun isEmpty [] = true
+ | isEmpty _ = false
+
+ fun fold f y s = foldr f y s
+
+ fun partition f s =
+ let fun partitionOne x l =
+ let fun findEqClass [] = [[x]]
+ | findEqClass (y::ys) = if f (x, (rep y))
+ then (x::y)::ys
+ else y::(findEqClass ys)
+ in findEqClass l
+ end
+ in foldr (fn (elem, classes) => partitionOne elem classes) [] s
+ end
+
+
+
+(* Dangerous, should be designed out. 2 sets are eq if they have the same
+ result for all shared tests. Thus the empty set is eq to all sets. Used to
+ avoid problems in subset if a solution has completed more tests than another
+ but has the same results on shared tests *) (* TODO : EDIT OUT *)
+ fun /==/ (set1, set2) =
+ let fun eq ((t1, num1, out1)::xs, (t2, num2, out2)::ys) =
+ (case cmpTests ((t1, num1), (t2, num2))
+ of LESS => eq (xs, (t2, num2, out2)::ys)
+ | GREATER => eq ((t1, num1, out1)::xs, ys)
+ | EQUAL => if Outcome.eq (out1, out2) then eq (xs, ys)
+ else false)
+ | eq ([], _) = true
+ | eq (_, _) = true
+ val (_,list1) = rep set1
+ val (_,list2) = rep set2
+ in eq (list1, list2)
+ end
+
+fun member (x, y) = raise NotImplemented
+(*
+ fun member ((id, ol), s) =
+ let val tmpSet = add ((id, ol), empty)
+ in List.exists (fn (id2, ol2) => /==/ ((id2, ol2), tmpSet)) s
+ end
+*)
+(* A < B iff for all shared tests, if A has passed, B has passed *)
+ fun /<=/ (set1, set2) =
+ let fun cmp ((t1, num1, out1)::xs, (t2, num2, out2)::ys) =
+ (case cmpTests ((t1, num1), (t2, num2))
+ of LESS => cmp (xs, (t2, num2, out2)::ys)
+ | GREATER => cmp ((t1, num1, out1)::xs, ys)
+ | EQUAL => (case Outcome.compare (out1, out2)
+ of GREATER => false
+ | _ => true ) )
+ | cmp ([], _) = true
+ | cmp (_, _) = true
+ val (_,list1) = rep set1
+ val (_,list2) = rep set2
+ in cmp (list1, list2)
+ end
+
+ fun /*/ (_,_)= raise NotImplemented
+ fun /+/ (_,_)= raise NotImplemented
+ fun /-/ (_,_)= raise NotImplemented
+
+end
@@ -1,15 +1,18 @@
-functor Set (Outcome : OUTCOME) : SET = struct
- type elem = (string * int * (string * Outcome.outcome) list)
+functor TestSet (Outcome : OUTCOME) : SET = struct
+ type elem = (string * string * (string * Outcome.outcome) list)
type set = elem list
exception NotFound
- exception NotFinished
+ exception NotImplemented
+
+(* Helper functions *)
+
fun insertion_sort _ [] = []
| insertion_sort cmp (x::xs) = insert cmp x (insertion_sort cmp xs)
and insert _ x [] = [x]
- | insert cmp x (l as y::ys) =
+ | insert cmp x (l as y::ys) =
case cmp (x, y) of GREATER => y :: insert cmp x ys
| _ => x :: l
fun cmpResultName ((x, _), (y, _)) = String.compare (x, y)
@@ -22,6 +25,9 @@ fun eqResult ((id, num, ol), (id2, num2, ol2)) =
Outcome.eq (out1, out2) andalso flag) true (ol, ol2)
handle UnequalLengths => false)
+
+
+(* real functions *)
val empty = []
fun add (x, s) = x::s
@@ -50,11 +56,11 @@ fun eqResult ((id, num, ol), (id2, num2, ol2)) =
in foldr (fn (elem, classes) => partitionOne elem classes) [] s
end
- fun /<=/ (_,_) = raise NotFinished
+ fun /<=/ (_,_) = raise NotImplemented
fun /==/ (set1, set2) = eqResult (rep set1, rep set2)
- fun /*/ (_,_) = raise NotFinished
- fun /+/ (_,_) = raise NotFinished
- fun /-/ (_,_) = raise NotFinished
+ fun /*/ (_,_) = raise NotImplemented
+ fun /+/ (_,_) = raise NotImplemented
+ fun /-/ (_,_) = raise NotImplemented
end

0 comments on commit 4bf79f9

Please sign in to comment.