Skip to content

Commit 3bd055d

Browse files
committed
test(tower): add remaining wheats and chaffs
1 parent d1c67be commit 3bd055d

File tree

20 files changed

+196
-6
lines changed

20 files changed

+196
-6
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fun first-floor(building :: Building) -> Option<Building%(is-story)>:
2+
none
3+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
fun first-floor(building :: Building) -> Option<Building%(is-story)> block:
2+
# return the second from the ground
3+
cases(Building) building:
4+
| ground => none
5+
| story(_, _, _, below-1) =>
6+
cases(Building) below-1:
7+
| ground => none
8+
| story(_, _, _, below-2) =>
9+
cases(Building) below-2:
10+
| ground => some(building)
11+
| else => first-floor(below-1)
12+
end
13+
end
14+
end
15+
end
16+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# this is somewhat pathological
2+
fun first-floor(building :: Building) -> Option<Building%(is-story)> block:
3+
cases(Building) building:
4+
| ground => none
5+
| story(_, _, _, below-1) =>
6+
cases(Building) below-1:
7+
| ground => none
8+
| story(_, _, _, below-2) =>
9+
cases(Building) below-2:
10+
| ground => some(below-1)
11+
| else => first-floor(below-1)
12+
end
13+
end
14+
end
15+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# this is somewhat pathological
2+
fun first-floor(building :: Building) -> Option<Building%(is-story)> block:
3+
cases(Building) building:
4+
| ground => none
5+
| story(_, _, _, below-1) =>
6+
cases(Building) below-1:
7+
| ground => none
8+
| story(_, _, _, below-2) =>
9+
cases(Building) below-2:
10+
| ground => some(below-1)
11+
| else => first-floor(below-2)
12+
end
13+
end
14+
end
15+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fun first-floor(building :: Building) -> Option<Building%(is-story)>:
2+
cases(Building) building:
3+
| ground => none
4+
| story(_, _, _, below) =>
5+
cases(Building) below:
6+
| ground => some(building)
7+
| else => first-floor(below)
8+
end
9+
end
10+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fun first-floor(building :: Building) -> Option<Building%(is-story)>:
2+
fun help(shadow building :: Building, acc :: Option<Building%(is-story)>):
3+
cases(Building) building:
4+
| ground => acc
5+
| story(_, _, _, below) => help(below, some(building))
6+
end
7+
end
8+
9+
help(building, none)
10+
end
11+

tests/examples/tower-grading/functionality.arr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
check "num-rooms: functionality":
2-
1 is 1
2+
num-rooms(ground) is 0
33
end
44

55
check "max-rooms: functionality":
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fun is-unbalanced(building :: Building) -> Boolean:
2+
cases(Building) building:
3+
| ground => false
4+
| story(_, rooms-above, _, below) =>
5+
cases(Building) below:
6+
| ground => false
7+
| story(_, rooms-below, _, _) =>
8+
(rooms-below <= rooms-above) or is-unbalanced(below)
9+
end
10+
end
11+
end
12+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fun is-unbalanced(building :: Building) -> Boolean:
2+
cases(Building) building:
3+
| ground => false
4+
| story(_, rooms-above, _, below) =>
5+
cases(Building) below:
6+
| ground => false
7+
| story(_, rooms-below, _, _) =>
8+
(rooms-below > rooms-above) or is-unbalanced(below)
9+
end
10+
end
11+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fun is-unbalanced(building :: Building) -> Boolean:
2+
cases(Building) building:
3+
| ground => true
4+
| story(_, rooms-above, _, below) =>
5+
cases(Building) below:
6+
| ground => true
7+
| story(_, rooms-below, _, _) =>
8+
(rooms-below >= rooms-above) and is-unbalanced(below)
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)