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.

📦 Turbo MoonBit cc1f595 · on main · k33g · 11h ago
shapes_test.mbt · 50 lines · 1.4 KBMoonBit Blame HistoryRaw
 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
// Blackbox tests: they see the package's public surface only, exactly as
// another package would. Run them with `moon test`, or from the editor's
// MoonBit menu with **Test**.

///|
test "a circle knows its area" {
  let c = @shapes.Circle::{ radius: 2.0, }
  assert_true((c.area() - 12.566370614359172).abs() < 1.0e-9)
}

///|
test "a rectangle knows its area" {
  assert_eq(@shapes.Rect::{ width: 3.0, height: 4.0, }.area(), 12.0)
}

///|
test "total adds every shape up" {
  let rects = [
    @shapes.Rect::{ width: 2.0, height: 2.0, },
    @shapes.Rect::{ width: 1.0, height: 5.0, },
  ]
  assert_eq(@shapes.total(rects), 9.0)
}

///|
/// `catch` names the error; `noraise` is the branch taken when nothing was
/// raised at all, which is what makes this a real assertion rather than a
/// test that passes either way.
test "total refuses an empty list" {
  let empty : Array[@shapes.Rect] = []
  try ignore(@shapes.total(empty)) catch {
    @shapes.NoShapes => ()
  } noraise {
    _ => fail("an empty list should have raised NoShapes")
  }
}

///|
test "largest picks the biggest, and None when there is nothing" {
  let rects = [
    @shapes.Rect::{ width: 1.0, height: 1.0, },
    @shapes.Rect::{ width: 9.0, height: 9.0, },
  ]
  assert_eq(
    @shapes.largest(rects),
    Some(@shapes.Rect::{ width: 9.0, height: 9.0, }),
  )
  let empty : Array[@shapes.Rect] = []
  assert_eq(@shapes.largest(empty), None)
}