/* ----------------------------------------------------------------------------- Copyright 2021 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] testcase "counter tests" { success } unittest zeroIndexed { Int index <- 0 traverse (Counter.zeroIndexed(10) -> Int i) { \ Testing.checkEquals(i,index) index <- index+1 } \ Testing.checkEquals(index,10) } unittest revZeroIndexed { Int index <- 10 traverse (Counter.revZeroIndexed(10) -> Int i) { index <- index-1 \ Testing.checkEquals(i,index) } \ Testing.checkEquals(index,0) } unittest unlimitedCount { Int index <- 0 traverse (Counter.unlimited() -> Int i) { \ Testing.checkEquals(i,index) if ((index <- index+1) >= 10) { break } } \ Testing.checkEquals(index,10) } unittest times { Int index <- 0 traverse ("message" `Repeat:times` 10 -> String m) { \ Testing.checkEquals(m,"message") index <- index+1 } \ Testing.checkEquals(index,10) } unittest unlimitedValue { Int index <- 0 traverse (Repeat:unlimited("message") -> String m) { \ Testing.checkEquals(m,"message") if ((index <- index+1) >= 10) { break } } \ Testing.checkEquals(index,10) } unittest minMax { scoped { Int x, Int y <- Ranges:minMax(10,3) } in { \ Testing.checkEquals(x,3) \ Testing.checkEquals(y,10) } scoped { Int x, Int y <- Ranges:minMax(3,10) } in { \ Testing.checkEquals(x,3) \ Testing.checkEquals(y,10) } } unittest min { scoped { Int x <- Ranges:min(10,3) } in \ Testing.checkEquals(x,3) scoped { Int x <- Ranges:min(3,10) } in \ Testing.checkEquals(x,3) } unittest max { scoped { Int x <- Ranges:max(10,3) } in \ Testing.checkEquals(x,10) scoped { Int x <- Ranges:max(3,10) } in \ Testing.checkEquals(x,10) }