// 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) }