Skip to content

Commit

Permalink
feat(builtin): add labeld_break function with tests for various sce…
Browse files Browse the repository at this point in the history
…narios
  • Loading branch information
bobzhang committed Dec 24, 2024
1 parent 86d7a26 commit e4c500e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions builtin/feature_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,33 @@ test {
@json.inspect!(my_range(1, 10), content={ "lo": 1, "hi": 10 })
@json.inspect!(my_range("a", "z"), content={ "lo": "a", "hi": "z" })
}

///|
fn labeld_break(xss : Array[Array[Double]]) -> Double? {
let mut threshold = 0.0
mylabel~: for xs in xss {
for x in xs {
threshold += x
if threshold > 10.0 {
break mylabel~ Some(threshold)
}
}
} else {
None
}
}

test "labeld_break/empty" {
let xss : Array[Array[Double]] = []
inspect!(labeld_break(xss), content="None")
}

test "labeld_break/sum_under_threshold" {
let xss = [[1.0, 2.0], [3.0, 4.0]]
inspect!(labeld_break(xss), content="None")
}

test "labeld_break/cross_threshold" {
let xss = [[3.0, 4.0], [5.0, 6.0]]
inspect!(labeld_break(xss), content="Some(12)")
}

0 comments on commit e4c500e

Please sign in to comment.