turbo-editors/turbo-moonbitpublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-moonbit.git
git clone ssh://git@rickub.com/turbo-editors/turbo-moonbit.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

shapes_test.mbt · 50 lines · 1.4 KBMoonBit Blame HistoryRaw
📦 Turbo MoonBit cc1f595 k33g 13h ago1// Blackbox tests: they see the package's public surface only, exactly as
2// another package would. Run them with `moon test`, or from the editor's
3// MoonBit menu with **Test**.
4
5///|
6test "a circle knows its area" {
7 let c = @shapes.Circle::{ radius: 2.0, }
8 assert_true((c.area() - 12.566370614359172).abs() < 1.0e-9)
9}
10
11///|
12test "a rectangle knows its area" {
13 assert_eq(@shapes.Rect::{ width: 3.0, height: 4.0, }.area(), 12.0)
14}
15
16///|
17test "total adds every shape up" {
18 let rects = [
19 @shapes.Rect::{ width: 2.0, height: 2.0, },
20 @shapes.Rect::{ width: 1.0, height: 5.0, },
21 ]
22 assert_eq(@shapes.total(rects), 9.0)
23}
24
25///|
26/// `catch` names the error; `noraise` is the branch taken when nothing was
27/// raised at all, which is what makes this a real assertion rather than a
28/// test that passes either way.
29test "total refuses an empty list" {
30 let empty : Array[@shapes.Rect] = []
31 try ignore(@shapes.total(empty)) catch {
32 @shapes.NoShapes => ()
33 } noraise {
34 _ => fail("an empty list should have raised NoShapes")
35 }
36}
37
38///|
39test "largest picks the biggest, and None when there is nothing" {
40 let rects = [
41 @shapes.Rect::{ width: 1.0, height: 1.0, },
42 @shapes.Rect::{ width: 9.0, height: 9.0, },
43 ]
44 assert_eq(
45 @shapes.largest(rects),
46 Some(@shapes.Rect::{ width: 9.0, height: 9.0, }),
47 )
48 let empty : Array[@shapes.Rect] = []
49 assert_eq(@shapes.largest(empty), None)
50}