Skip to content

Instantly share code, notes, and snippets.

@kvalle
Last active December 14, 2015 19:29
Show Gist options
  • Select an option

  • Save kvalle/5137378 to your computer and use it in GitHub Desktop.

Select an option

Save kvalle/5137378 to your computer and use it in GitHub Desktop.
Provided tests for SML part of HW7 in Coursera course on programming languages, re-written to work with https://github.com/kvalle/sml-testing
(* University of Washington, Programming Languages, Homework 7
hw7testsprovided.sml *)
(* Will not compile until you implement preprocess and eval_prog *)
(* Re-written to work with https://github.com/kvalle/sml-testing *)
(* These tests do NOT cover all the various cases, especially for intersection *)
use "hw7.sml";
use "testing.sml";
open SmlTests;
(* Must implement preprocess_prog and Shift before running these tests *)
fun real_equal(x,y) = Real.compare(x,y) = General.EQUAL;
(* Preprocess tests *)
test("preprocess converts a LineSegment to a Point successfully",
assert_true(
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
real_equal(a,c) andalso real_equal(b,d)
end));
test("preprocess flips an improper LineSegment successfully",
assert_true(
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
real_equal(a,e) andalso real_equal(b,f) andalso real_equal(c,g) andalso real_equal(d,h)
end));
(* eval_prog tests with Shift*)
test("eval_prog with empty environment worked",
assert_true(
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
real_equal(a,c) andalso real_equal(b,d)
end));
(* Using a Var *)
test("eval_prog with 'a' in environment is working properly",
assert_true(
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
real_equal(a,c) andalso real_equal(b,d)
end));
(* With Variable Shadowing *)
test("eval_prog with shadowing 'a' in environment is working properly",
assert_true(
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
real_equal(a,c) andalso real_equal(b,d)
end));
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment