/* ----------------------------------------------------------------------------- Copyright 2021,2023 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 "comparator helper tests" { success TestChecker } unittest keyValueHLessThan { \ (KV.new(1, "a") `KeyValueH:lessThan` KV.new(1, "a")) `Matches:with` CheckValue:equals(false) \ (KV.new(1, "a") `KeyValueH:lessThan` KV.new(1, "b")) `Matches:with` CheckValue:equals(true) \ (KV.new(2, "a") `KeyValueH:lessThan` KV.new(1, "b")) `Matches:with` CheckValue:equals(false) \ (KV.new(1, "b") `KeyValueH:lessThan` KV.new(2, "a")) `Matches:with` CheckValue:equals(true) } unittest keyValueHLessThanWith { \ (KV.new(1, "a") `KeyValueH:lessThanWith` KV.new(1, "a")) `Matches:with` CheckValue:equals(false) \ (KV.new(1, "a") `KeyValueH:lessThanWith` KV.new(1, "b")) `Matches:with` CheckValue:equals(false) \ (KV.new(2, "a") `KeyValueH:lessThanWith` KV.new(1, "b")) `Matches:with` CheckValue:equals(false) \ (KV.new(1, "b") `KeyValueH:lessThanWith` KV.new(2, "a")) `Matches:with` CheckValue:equals(true) \ (KV.new(1, "a") `KeyValueH:lessThanWith` KV.new(1, "a")) `Matches:with` CheckValue:equals(false) \ (KV.new(1, "a") `KeyValueH:lessThanWith` KV.new(1, "b")) `Matches:with` CheckValue:equals(true) \ (KV.new(2, "a") `KeyValueH:lessThanWith` KV.new(1, "b")) `Matches:with` CheckValue:equals(true) \ (KV.new(1, "b") `KeyValueH:lessThanWith` KV.new(2, "a")) `Matches:with` CheckValue:equals(false) } unittest keyValueHEquals { \ (KV.new(1, "a") `KeyValueH:equals` KV.new(1, "a")) `Matches:with` CheckValue:equals(true) \ (KV.new(1, "a") `KeyValueH:equals` KV.new(1, "b")) `Matches:with` CheckValue:equals(false) \ (KV.new(2, "a") `KeyValueH:equals` KV.new(1, "b")) `Matches:with` CheckValue:equals(false) \ (KV.new(1, "b") `KeyValueH:equals` KV.new(2, "a")) `Matches:with` CheckValue:equals(false) } unittest keyValueHEqualsWith { \ (KV.new(1, "a") `KeyValueH:equalsWith` KV.new(1, "a")) `Matches:with` CheckValue:equals(true) \ (KV.new(1, "a") `KeyValueH:equalsWith` KV.new(1, "b")) `Matches:with` CheckValue:equals(true) \ (KV.new(2, "a") `KeyValueH:equalsWith` KV.new(1, "b")) `Matches:with` CheckValue:equals(false) \ (KV.new(1, "b") `KeyValueH:equalsWith` KV.new(2, "a")) `Matches:with` CheckValue:equals(false) \ (KV.new(1, "a") `KeyValueH:equalsWith` KV.new(1, "a")) `Matches:with` CheckValue:equals(true) \ (KV.new(1, "a") `KeyValueH:equalsWith` KV.new(1, "b")) `Matches:with` CheckValue:equals(false) \ (KV.new(2, "a") `KeyValueH:equalsWith` KV.new(1, "b")) `Matches:with` CheckValue:equals(false) \ (KV.new(1, "b") `KeyValueH:equalsWith` KV.new(2, "a")) `Matches:with` CheckValue:equals(false) } unittest integrationTest { SortedMap map1 <- SortedMap.new() .set(1, "d").set(2, "c").set(3, "b").set(4, "a") SortedMap map2 <- SortedMap.new() .set(1, "a").set(2, "b").set(3, "c").set(4, "d") \ (map1.defaultOrder() `OrderH:equalsWith>` map2.defaultOrder()) `Matches:with` CheckValue:equals(true) \ (map1.defaultOrder() `OrderH:equalsWith>` map2.defaultOrder()) `Matches:with` CheckValue:equals(false) \ (map1.defaultOrder() `OrderH:equalsWith>` map2.defaultOrder()) `Matches:with` CheckValue:equals(false) } concrete KVEquals<#k, #v> { defines Equals> #k defines Equals #v defines Equals } define KVEquals { equals (x, y) { return x `KeyValueH:equalsWith` y } } concrete KV { refines KeyValue @type new (Int, String) -> (KV) } define KV { $ReadOnly[key, value]$ @value Int key @value String value new (k, v) { return KV{ k, v } } getKey () { return key } getValue () { return value } }