-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheme_test.rb
114 lines (90 loc) · 2.26 KB
/
scheme_test.rb
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
require 'test/unit'
load 'scheme.rb'
class TestSchemeObjectAtom < Test::Unit::TestCase
def test_symbol_is_atom
assert :symbol.atom?
end
def test_string_is_atom
assert "foo".atom?
end
def test_numerics_are_atoms
assert 1.34.atom?
end
def test_lists_are_not_atoms
assert ![].atom?
end
end
class TestSchemeObjectSExpr < Test::Unit::TestCase
def test_atoms_are_sexprs
assert :symbol.sexpr?
end
def tests_lists_are_sexprs
assert [].sexpr?
end
end
class TestSchemeArrayListPredicate < Test::Unit::TestCase
def test_empty_lists_are_lists
assert [].list?
end
def test_flat_arrays_of_atoms_are_lists
assert [:a, "string and a", 3.14].list?
end
def test_deeply_nested_arrays_of_atoms_are_lists
assert [[:a, "different"], "type", [:of, 3.14]].list?
end
def test_atoms_are_not_lists
assert_raise(NoMethodError) { :a.list? }
end
end
class TestSchemeArrayNullPredicate < Test::Unit::TestCase
def test_empty_is_null
assert [].null?
end
def test_not_empty_is_not_null
assert ![:foo].null?
end
def test_null_of_atom_undefined
assert(NoMethodError) { :a.null? }
end
end
class TestSchemeDeconstruction < Test::Unit::TestCase
def test_car_of_atom_undefined
assert(NoMethodError) { :a.car }
end
def test_car_of_list
assert_equal :a, [:a, :b].car
end
def test_cdr_of_list
assert_equal [:b], [:a, :b].cdr
end
def test_crazy_dynamic_decomposition
assert_equal :d, [[], [[:b,:c,:d]]].caddaadr
end
end
class TestSchemeListConstruction < Test::Unit::TestCase
def test_cons_atom_to_list
assert_equal [:a, :b, :c], [:b, :c].cons(:a)
end
end
class TestSchemeListOfAtoms < Test::Unit::TestCase
def test_empty_list
assert [].lat?
end
def test_flat_list_of_atoms
assert [:a, "list", 3.14].lat?
end
def test_deep_list_is_not_a_list_of_atoms
assert ![[:a], :b, "list", 3.14].lat?
end
end
class TestSchemeListRemeber < Test::Unit::TestCase
def test_rember_of_empty_list
assert_equal [], [].rember(:a)
end
def test_rember_removes_first_matching_atom
assert_equal [:a, :c], [:a, :b, :c].rember(:b)
end
def test_remember_does_not_remove_remaining_matching_atoms
assert_equal [:a, :c, :b, :b], [:a, :b, :c, :b, :b].rember(:b)
end
end