-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw7testsprovided.sml
61 lines (51 loc) · 2.2 KB
/
hw7testsprovided.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(* University of Washington, Programming Languages, Homework 7
hw7testsprovided.sml *)
(* Will not compile until you implement preprocess and eval_prog *)
(* These tests do NOT cover all the various cases, especially for intersection *)
use "hw7.sml";
(* Must implement preprocess_prog and Shift before running these tests *)
fun real_equal(x,y) = Real.compare(x,y) = General.EQUAL;
(* Preprocess tests *)
let
val Point(a,b) = preprocess_prog(LineSegment(3.2,4.1,3.2,4.1))
val Point(c,d) = Point(3.2,4.1)
in
if real_equal(a,c) andalso real_equal(b,d)
then (print "preprocess converts a LineSegment to a Point successfully\n")
else (print "preprocess does not convert a LineSegment to a Point succesfully\n")
end;
let
val LineSegment(a,b,c,d) = preprocess_prog (LineSegment(3.2,4.1,~3.2,~4.1))
val LineSegment(e,f,g,h) = LineSegment(~3.2,~4.1,3.2,4.1)
in
if real_equal(a,e) andalso real_equal(b,f) andalso real_equal(c,g) andalso real_equal(d,h)
then (print "preprocess flips an improper LineSegment successfully\n")
else (print "preprocess does not flip an improper LineSegment successfully\n")
end;
(* eval_prog tests with Shift*)
let
val Point(a,b) = (eval_prog (preprocess_prog (Shift(3.0, 4.0, Point(4.0,4.0))), []))
val Point(c,d) = Point(7.0,8.0)
in
if real_equal(a,c) andalso real_equal(b,d)
then (print "eval_prog with empty environment worked\n")
else (print "eval_prog with empty environment is not working properly\n")
end;
(* Using a Var *)
let
val Point(a,b) = (eval_prog (Shift(3.0,4.0,Var "a"), [("a",Point(4.0,4.0))]))
val Point(c,d) = Point(7.0,8.0)
in
if real_equal(a,c) andalso real_equal(b,d)
then (print "eval_prog with 'a' in environment is working properly\n")
else (print "eval_prog with 'a' in environment is not working properly\n")
end;
(* With Variable Shadowing *)
let
val Point(a,b) = (eval_prog (Shift(3.0,4.0,Var "a"), [("a",Point(4.0,4.0)),("a",Point(1.0,1.0))]))
val Point(c,d) = Point(7.0,8.0)
in
if real_equal(a,c) andalso real_equal(b,d)
then (print "eval_prog with shadowing 'a' in environment is working properly\n")
else (print "eval_prog with shadowing 'a' in environment is not working properly\n")
end;