Skip to content

Commit

Permalink
Add tuple tests to tck
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Gleyzer committed Mar 7, 2024
1 parent ec398b3 commit b83ba3a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
3 changes: 3 additions & 0 deletions tck/src/main/x/tck.x
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ module tck.xtclang.org {

// constructors.Reflect r = new constructors.Reflect();
// r.testAssertChain();

// tuple.Basic t = new tuple.Basic();
// t.testSlice();
}
}
13 changes: 6 additions & 7 deletions tck/src/main/x/tck/array/Basic.x
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Very basic array tests.
*/
class Basic {

// -----------------------------
// Create; set; get; size
@Test
Expand Down Expand Up @@ -82,13 +82,13 @@ class Basic {
}

@Test
void mutImteralInts() {
void mutConstInts() {
Int[] array = [0, 1];
assert array.mutability == Constant;
}

@Test
void mutDefaultFixed() {
void mutDefaultInts() {
Int[] array = new Int[2];
assert array.mutability == Fixed;
}
Expand All @@ -111,7 +111,7 @@ class Basic {
assert array.mutability == Fixed;
}


// -----------------------------
// Plus add, delete, create allowing mutation
@Test
Expand Down Expand Up @@ -177,7 +177,6 @@ class Basic {
assert slice[2] == "four";
}


// -----------------------------

@Test
Expand Down Expand Up @@ -210,10 +209,10 @@ class Basic {
array = array.delete(1);
assert array.mutability == Constant;
}

// -----------------------------
// Remove, delete

@Test
void deleteUnordered() {
Int[] array = new Int[].addAll([7, 2, 5, 21, 13, 42]);
Expand Down
66 changes: 66 additions & 0 deletions tck/src/main/x/tck/tuple/Basic.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Basic tuple tests.
*/
class Basic {

@Test
void testConstAccess() {
Tuple<String, String, Int> t = ("hello", "world", 17);
assert t[0] == "hello";
assert t[2] == 17;
}

@Test
void testIndexAccess() {
Tuple t = ("hello", Int:17);
for (Int i : 0 ..< t.size) {
switch (i) {
case 0:
assert t[i].as(String) == "hello";
break;
case 1:
assert t[i].as(Int) == 17;
break;
}
}
}

@Test
void testEquality() {
static String BYE() = "goodbye";
Int four = 4;
String now = "now";

Tuple<String, Map<Int, String>> t1 = ("goodbye", [4="now"]);
Tuple<String, Map<Int, String>> t2 = Tuple:(BYE(), [four=now]);
assert t1 == t2;

Tuple<Int, String, Char> t3 = (1, "big", '?');
Tuple t4 = Tuple:().add(Int:1).add("big").add('?');
assert t3 == t4;
}

@Test
void testVoidConv() {
private static void getVoid() {}

Tuple tv = getVoid();
assert tv.size == 0;
}

@Test
void testIntConv() {
private static Int getInt() = 4;

Tuple<Int> ti = getInt();
assert ti.size == 1 && ti[0] == 4;
}

@Test
void testSlice() {
Int three = 3;
Tuple<Int, String, String, Char> t = (three, "blind", "mice", '!');
Tuple<String, String, Char> s = t[1..3];
assert s[three-1].as(Char) == s[2] == '!';
}
}

0 comments on commit b83ba3a

Please sign in to comment.