-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_tuples.dry
40 lines (35 loc) · 1.54 KB
/
test_tuples.dry
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
class TestTuple {
def test_init() {
let empty = ();
assert_equals("Empty tuple string representation", str(empty), "()");
assert_equals("An empty tuple is a unit", typeof(empty), "unit");
let singleton = (1,);
assert_equals("Singleton tuple string representation", str(singleton), "(1,)");
assert_equals("Singleton tuple type", typeof(singleton), "tuple");
assert_equals("Singleton tuple size", singleton.size(), 1);
let many = (1, "two", none);
assert_equals("Multiple-element string representation", str(many), "(1, two, none)");
assert_equals("Multiple-element tuple type", typeof(many), "tuple");
assert_equals("Multiple-element tuple size", many.size(), 3);
}
def test_get() {
let singleton = (1,);
assert_error_type("Reading tuple elements with string index", InvalidIndexError, lambda() {
singleton[""];
});
assert_error_type("Reading tuple elements with index < 0", IndexOutOfBoundsError, lambda() {
singleton[-1];
});
assert_error_type("Reading tuple elements with index == size", IndexOutOfBoundsError, lambda() {
singleton[1];
});
assert_error_type("Reading tuple elements with index > size", IndexOutOfBoundsError, lambda() {
singleton[2];
});
let many = (1, "two", none);
assert_equals("Reading tuple elements correctly", "two", many[1]);
}
}
let test_tuple = TestTuple();
test_tuple.test_init();
test_tuple.test_get();