How to use default method of io.kotest.equals.Equality class

Best Kotest code snippet using io.kotest.equals.Equality.default

FzyDoubleEqualityTest.kt

Source:FzyDoubleEqualityTest.kt Github

copy

Full Screen

...48 }49 test("unity") {50 val fd0 = FzyDouble(1.0)51 val fd00 = FzyDouble(1.0, doubleEps, true)52 val fd1 = FzyDouble(1.0+defaultDoubleTol)53 val fd2 = FzyDouble(1.0-defaultDoubleTol)54 val fd3 = FzyDouble(1.0+defaultDoubleTol, 2.0*defaultDoubleTol)55 val fd4 = FzyDouble(1.0-defaultDoubleTol, 2.0*defaultDoubleTol)56 fd0.isUnity() shouldBe true57 fd00.isUnity() shouldBe true58 fd1.isUnity() shouldBe false59 fd2.isUnity() shouldBe false60 fd3.isUnity() shouldBe true61 fd4.isUnity() shouldBe true62 1.0.fzyIsUnity() shouldBe true63 (1.0+defaultDoubleTol).fzyIsUnity() shouldBe false64 (1.0-defaultDoubleTol).fzyIsUnity() shouldBe false65 Double.NaN.fzyIsUnity() shouldBe false66 Double.NEGATIVE_INFINITY.fzyIsUnity() shouldBe false67 Double.POSITIVE_INFINITY.fzyIsUnity() shouldBe false68 }69 test("throw if defeated"){70 shouldThrow<IllegalArgumentException> {71 FzyDouble(1.0, doubleEps)72 }73 shouldThrow<IllegalArgumentException> {74 FzyDouble(1.0, -0.0004)75 }76 }77 test("bounds") {78 (FzyDouble(Double.MAX_VALUE) == FzyDouble(Double.MAX_VALUE)) shouldBe true79 (FzyDouble(-Double.MAX_VALUE) == FzyDouble(-Double.MAX_VALUE)) shouldBe true80 FzyDouble(Double.MAX_VALUE).equals(Double.MAX_VALUE) shouldBe true81 FzyDouble(-Double.MAX_VALUE).equals(-Double.MAX_VALUE) shouldBe true82 (FzyDouble(Double.MIN_VALUE) == FzyDouble(Double.MIN_VALUE)) shouldBe true83 (FzyDouble(Double.MIN_VALUE) == FzyDouble(-Double.MIN_VALUE)) shouldBe true84 (FzyDouble(-Double.MIN_VALUE) == FzyDouble(-Double.MIN_VALUE)) shouldBe true85 FzyDouble(Double.MIN_VALUE).equals(Double.MIN_VALUE) shouldBe true86 FzyDouble(Double.MIN_VALUE).equals(-Double.MIN_VALUE) shouldBe true87 FzyDouble(-Double.MIN_VALUE).equals(-Double.MIN_VALUE) shouldBe true88 Double.MAX_VALUE.fzyEqual(Double.MAX_VALUE) shouldBe true89 (-Double.MAX_VALUE).fzyEqual(-Double.MAX_VALUE) shouldBe true90 Double.MAX_VALUE.fzyEqual(FzyDouble(Double.MAX_VALUE)) shouldBe true91 (-Double.MAX_VALUE).fzyEqual(FzyDouble(-Double.MAX_VALUE)) shouldBe true92 Double.MIN_VALUE.fzyEqual(Double.MIN_VALUE) shouldBe true93 Double.MIN_VALUE.fzyEqual(-Double.MIN_VALUE) shouldBe true94 (-Double.MIN_VALUE).fzyEqual(-Double.MIN_VALUE) shouldBe true95 Double.MIN_VALUE.fzyEqual(FzyDouble(Double.MIN_VALUE)) shouldBe true96 Double.MIN_VALUE.fzyEqual(FzyDouble(-Double.MIN_VALUE)) shouldBe true97 (-Double.MIN_VALUE).fzyEqual(FzyDouble(-Double.MIN_VALUE)) shouldBe true98 }99 test("underflow") {100 (FzyDouble(Double.MAX_VALUE) == FzyDouble(1E-20)) shouldBe false101 (FzyDouble(-Double.MAX_VALUE) == FzyDouble(-1E-20)) shouldBe false102 FzyDouble(Double.MAX_VALUE).equals(1E-20) shouldBe false103 FzyDouble(-Double.MAX_VALUE).equals(-1E-20) shouldBe false104 }105 test("overflow") {106 (FzyDouble(1E-20) == FzyDouble(Double.MAX_VALUE)) shouldBe false107 (FzyDouble(-1E-20) == FzyDouble(-Double.MAX_VALUE)) shouldBe false108 FzyDouble(1E-20).equals(Double.MAX_VALUE) shouldBe false109 FzyDouble(-1E-20).equals(-Double.MAX_VALUE) shouldBe false110 }111 test("same zeroes") {112 val fd0a = FzyDouble.zero()113 val fd0b = FzyDouble.zero()114 val fd00 = FzyDouble.zero(defaultDoubleTol*2.0)115 val fd1 = FzyDouble.unity()116 FzyDoubleEquality.isSameZeroes(fd0a, fd0a) shouldBe true117 FzyDoubleEquality.isSameZeroes(fd0a, fd0b) shouldBe true118 FzyDoubleEquality.isSameZeroes(fd0b, fd0a) shouldBe true119 FzyDoubleEquality.isSameZeroes(fd0a, fd00) shouldBe false120 FzyDoubleEquality.isSameZeroes(fd00, fd0a) shouldBe false121 FzyDoubleEquality.isSameZeroes(fd0a, fd1) shouldBe false122 FzyDoubleEquality.isSameZeroes(fd1, fd0a) shouldBe false123 }124 test("double properties, reflexive") {125 checkAll(Arb.double(), Arb.numericDoubles()) { f1, f2 ->126 val ff1a = FzyDouble(f1)127 val ff1b = FzyDouble(f1)128 val ff2a = FzyDouble(f2)129 val ff2b = FzyDouble(f2)130 ff1a.equals(f1) shouldBe !f1.isNaN()131 ff1b.equals(f1) shouldBe !f1.isNaN()132 ff2a.equals(f2) shouldBe true133 ff2b.equals(f2) shouldBe true134 f1.fzyEqual(f1) shouldBe !f1.isNaN()135 f1.fzyEqual(ff1a) shouldBe !f1.isNaN()136 f1.fzyEqual(ff1b) shouldBe !f1.isNaN()137 ff1a.equals(f1) shouldBe !f1.isNaN()138 ff1b.equals(f1) shouldBe !f1.isNaN()139 (ff1a == ff1b) shouldBe !f1.isNaN()140 (ff1b == ff1a) shouldBe !f1.isNaN()141 ff2a.equals(f2) shouldBe true142 ff2b.equals(f2) shouldBe true143 (ff2a == ff2b) shouldBe true144 (ff2b == ff2a) shouldBe true145 }146 }147 test("double properties, symmetric") {148 checkAll(Arb.double(), Arb.numericDoubles()) { f1, f2 ->149 val ff1 = FzyDouble(f1)150 val f1d = f1 / (1.0 + (defaultDoubleTol /2.0))151 val ff1d = FzyDouble(f1d)152 val ff2 = FzyDouble(f2)153 val f2d = f2 / (1.0 + (defaultDoubleTol /2.0))154 val ff2d = FzyDouble(f2d)155 (!ff1.equals(f1d) && f1.fzyIsZero()) shouldBe false156 (f1.fzyIsZero() && ff1 != ff1d) shouldBe false157 f1.fzyEqual(f1d) shouldBe !f1.isNaN()158 f1.fzyEqual(ff1d) shouldBe !f1.isNaN()159 f1d.fzyEqual(f1) shouldBe !f1.isNaN()160 f1d.fzyEqual(ff1) shouldBe !f1.isNaN()161 ff1.equals(f1d) shouldBe !f1.isNaN()162 (ff1d == ff1) shouldBe !f1.isNaN()163 ff1d.equals(f1) shouldBe !f1.isNaN()164 ff1.equals(f1d) shouldBe !f1.isNaN()165 (!ff2.equals(f2d) && f2.fzyIsZero()) shouldBe false166 (f2.fzyIsZero() && ff2 != ff2d) shouldBe false167 f2.fzyEqual(f2d) shouldBe true168 f2.fzyEqual(ff2d) shouldBe true169 f2d.fzyEqual(f2) shouldBe true170 f2d.fzyEqual(ff2) shouldBe true171 ff2.equals(f2d) shouldBe true172 (ff2d == ff2) shouldBe true173 ff2d.equals(f2) shouldBe true174 ff2.equals(f2d) shouldBe true175 }176 }177 test("double properties, transitive") {178 checkAll(Arb.double(), Arb.numericDoubles()) { f1, f2 ->179 val ff1 = FzyDouble(f1)180 val f1a = f1 / (1.0 + (defaultDoubleTol /1.7))181 val ff1a = FzyDouble(f1a)182 val f1b = f1 / (1.0 + (defaultDoubleTol /1.3))183 val ff1b = FzyDouble(f1b)184 val ff2 = FzyDouble(f2)185 val f2a = f2 / (1.0 + (defaultDoubleTol /1.9))186 val ff2a = FzyDouble(f2a)187 val f2b = f2 / (1.0 + (defaultDoubleTol /1.5))188 val ff2b = FzyDouble(f2b)189 (!ff1.equals(f1a) && f1.fzyIsZero()) shouldBe false190 (f1.fzyIsZero() && ff1 != ff1a) shouldBe false191 (!ff1.equals(f1b) && f1.fzyIsZero()) shouldBe false192 (f1.fzyIsZero() && ff1 != ff1b) shouldBe false193 // f1 == f1a, f1a == f1b => f1 == f1b194 f1.fzyEqual(f1a) shouldBe !f1.isNaN()195 f1.fzyEqual(ff1a) shouldBe !f1.isNaN()196 f1a.fzyEqual(f1b) shouldBe !f1.isNaN()197 f1a.fzyEqual(ff1b) shouldBe !f1.isNaN()198 f1b.fzyEqual(f1) shouldBe !f1.isNaN()199 f1b.fzyEqual(ff1) shouldBe !f1.isNaN()200 ff1.equals(f1a) shouldBe !f1.isNaN()201 (ff1 == ff1a) shouldBe !f1.isNaN()...

Full Screen

Full Screen

FzyFloatEqualityTest.kt

Source:FzyFloatEqualityTest.kt Github

copy

Full Screen

...48 }49 test("unity") {50 val fd0 = FzyFloat(1.0f)51 val fd00 = FzyFloat(1.0f, floatEps, true)52 val fd1 = FzyFloat(1.0f+defaultFloatTol)53 val fd2 = FzyFloat(1.0f-defaultFloatTol)54 val fd3 = FzyFloat(1.0f+defaultFloatTol, 2.0f*defaultFloatTol)55 val fd4 = FzyFloat(1.0f-defaultFloatTol, 2.0f*defaultFloatTol)56 fd0.isUnity() shouldBe true57 fd00.isUnity() shouldBe true58 fd1.isUnity() shouldBe false59 fd2.isUnity() shouldBe false60 fd3.isUnity() shouldBe true61 fd4.isUnity() shouldBe true62 1.0f.fzyIsUnity() shouldBe true63 (1.0f+defaultFloatTol).fzyIsUnity() shouldBe false64 (1.0f-defaultFloatTol).fzyIsUnity() shouldBe false65 Float.NaN.fzyIsUnity() shouldBe false66 Float.NEGATIVE_INFINITY.fzyIsUnity() shouldBe false67 Float.POSITIVE_INFINITY.fzyIsUnity() shouldBe false68 }69 test("throw if defeated"){70 shouldThrow<IllegalArgumentException> {71 FzyFloat(1.0f, floatEps)72 }73 shouldThrow<IllegalArgumentException> {74 FzyFloat(1.0f, -0.0004f)75 }76 }77 test("bounds") {78 (FzyFloat(Float.MAX_VALUE) == FzyFloat(Float.MAX_VALUE)) shouldBe true79 (FzyFloat(-Float.MAX_VALUE) == FzyFloat(-Float.MAX_VALUE)) shouldBe true80 FzyFloat(Float.MAX_VALUE).equals(Float.MAX_VALUE) shouldBe true81 FzyFloat(-Float.MAX_VALUE).equals(-Float.MAX_VALUE) shouldBe true82 (FzyFloat(Float.MIN_VALUE) == FzyFloat(Float.MIN_VALUE)) shouldBe true83 (FzyFloat(Float.MIN_VALUE) == FzyFloat(-Float.MIN_VALUE)) shouldBe true84 (FzyFloat(-Float.MIN_VALUE) == FzyFloat(-Float.MIN_VALUE)) shouldBe true85 FzyFloat(Float.MIN_VALUE).equals(Float.MIN_VALUE) shouldBe true86 FzyFloat(Float.MIN_VALUE).equals(-Float.MIN_VALUE) shouldBe true87 FzyFloat(-Float.MIN_VALUE).equals(-Float.MIN_VALUE) shouldBe true88 Float.MAX_VALUE.fzyEqual(Float.MAX_VALUE) shouldBe true89 (-Float.MAX_VALUE).fzyEqual(-Float.MAX_VALUE) shouldBe true90 Float.MAX_VALUE.fzyEqual(FzyFloat(Float.MAX_VALUE)) shouldBe true91 (-Float.MAX_VALUE).fzyEqual(FzyFloat(-Float.MAX_VALUE)) shouldBe true92 Float.MIN_VALUE.fzyEqual(Float.MIN_VALUE) shouldBe true93 Float.MIN_VALUE.fzyEqual(-Float.MIN_VALUE) shouldBe true94 (-Float.MIN_VALUE).fzyEqual(-Float.MIN_VALUE) shouldBe true95 Float.MIN_VALUE.fzyEqual(FzyFloat(Float.MIN_VALUE)) shouldBe true96 Float.MIN_VALUE.fzyEqual(FzyFloat(-Float.MIN_VALUE)) shouldBe true97 (-Float.MIN_VALUE).fzyEqual(FzyFloat(-Float.MIN_VALUE)) shouldBe true98 }99 test("underflow") {100 (FzyFloat(Float.MAX_VALUE) == FzyFloat(1E-10f)) shouldBe false101 (FzyFloat(-Float.MAX_VALUE) == FzyFloat(-1E-10f)) shouldBe false102 FzyFloat(Float.MAX_VALUE).equals(1E-10f) shouldBe false103 FzyFloat(-Float.MAX_VALUE).equals(-1E-10f) shouldBe false104 }105 test("overflow") {106 (FzyFloat(1E-10f) == FzyFloat(Float.MAX_VALUE)) shouldBe false107 (FzyFloat(-1E-10f) == FzyFloat(-Float.MAX_VALUE)) shouldBe false108 FzyFloat(1E-10f).equals(Float.MAX_VALUE) shouldBe false109 FzyFloat(-1E-10f).equals(-Float.MAX_VALUE) shouldBe false110 }111 test("same zeroes") {112 val fd0a = FzyFloat.zero()113 val fd0b = FzyFloat.zero()114 val fd00 = FzyFloat.zero(defaultFloatTol*2.0f)115 val fd1 = FzyFloat.unity()116 FzyFloatEquality.isSameZeroes(fd0a, fd0a) shouldBe true117 FzyFloatEquality.isSameZeroes(fd0a, fd0b) shouldBe true118 FzyFloatEquality.isSameZeroes(fd0b, fd0a) shouldBe true119 FzyFloatEquality.isSameZeroes(fd0a, fd00) shouldBe false120 FzyFloatEquality.isSameZeroes(fd00, fd0a) shouldBe false121 FzyFloatEquality.isSameZeroes(fd0a, fd1) shouldBe false122 FzyFloatEquality.isSameZeroes(fd1, fd0a) shouldBe false123 }124 test("float properties, reflexive") {125 checkAll(Arb.float(), Arb.numericFloats()) { f1, f2 ->126 val ff1a = FzyFloat(f1)127 val ff1b = FzyFloat(f1)128 val ff2a = FzyFloat(f2)129 val ff2b = FzyFloat(f2)130 ff1a.equals(f1) shouldBe !f1.isNaN()131 ff1b.equals(f1) shouldBe !f1.isNaN()132 ff2a.equals(f2) shouldBe true133 ff2b.equals(f2) shouldBe true134 f1.fzyEqual(f1) shouldBe !f1.isNaN()135 f1.fzyEqual(ff1a) shouldBe !f1.isNaN()136 f1.fzyEqual(ff1b) shouldBe !f1.isNaN()137 ff1a.equals(f1) shouldBe !f1.isNaN()138 ff1b.equals(f1) shouldBe !f1.isNaN()139 (ff1a == ff1b) shouldBe !f1.isNaN()140 (ff1b == ff1a) shouldBe !f1.isNaN()141 ff2a.equals(f2) shouldBe true142 ff2b.equals(f2) shouldBe true143 (ff2a == ff2b) shouldBe true144 (ff2b == ff2a) shouldBe true145 }146 }147 test("float properties, symmetric") {148 checkAll(Arb.float(), Arb.numericFloats()) { f1, f2 ->149 val ff1 = FzyFloat(f1)150 val f1d = ff1.qty / (1.0f + (defaultFloatTol /2.0f))151 val ff1d = FzyFloat(f1d)152 val ff2 = FzyFloat(f2)153 val f2d = ff2.qty / (1.0f + (defaultFloatTol /2.0f))154 val ff2d = FzyFloat(f2d)155 (!ff1.equals(f1d) && f1.fzyIsZero()) shouldBe false156 (f1.fzyIsZero() && ff1 != ff1d) shouldBe false157 f1.fzyEqual(f1d) shouldBe !f1.isNaN()158 f1.fzyEqual(ff1d) shouldBe !f1.isNaN()159 f1d.fzyEqual(f1) shouldBe !f1.isNaN()160 f1d.fzyEqual(ff1) shouldBe !f1.isNaN()161 ff1.equals(f1d) shouldBe !f1.isNaN()162 (ff1d == ff1) shouldBe !f1.isNaN()163 ff1d.equals(f1) shouldBe !f1.isNaN()164 ff1.equals(f1d) shouldBe !f1.isNaN()165 (!ff2.equals(f2d) && f2.fzyIsZero()) shouldBe false166 (f2.fzyIsZero() && ff2 != ff2d) shouldBe false167 f2.fzyEqual(f2d) shouldBe true168 f2.fzyEqual(ff2d) shouldBe true169 f2d.fzyEqual(f2) shouldBe true170 f2d.fzyEqual(ff2) shouldBe true171 ff2.equals(f2d) shouldBe true172 (ff2d == ff2) shouldBe true173 ff2d.equals(f2) shouldBe true174 ff2.equals(f2d) shouldBe true175 }176 }177 test("float properties, transitive") {178 checkAll(Arb.float(), Arb.numericFloats()) { f1, f2 ->179 val ff1 = FzyFloat(f1)180 val f1a = f1 / (1.0f + (defaultFloatTol /1.7f))181 val ff1a = FzyFloat(f1a)182 val f1b = f1 / (1.0f + (defaultFloatTol /1.3f))183 val ff1b = FzyFloat(f1b)184 val ff2 = FzyFloat(f2)185 val f2a = f2 / (1.0f + (defaultFloatTol /1.9f))186 val ff2a = FzyFloat(f2a)187 val f2b = f2 / (1.0f + (defaultFloatTol /1.5f))188 val ff2b = FzyFloat(f2b)189 (!ff1.equals(f1a) && f1.fzyIsZero()) shouldBe false190 (f1.fzyIsZero() && ff1 != ff1a) shouldBe false191 (!ff1.equals(f1b) && f1.fzyIsZero()) shouldBe false192 (f1.fzyIsZero() && ff1 != ff1b) shouldBe false193 // f1 == f1a, f1a == f1b => f1 == f1b194 f1.fzyEqual(f1a) shouldBe !f1.isNaN()195 f1.fzyEqual(ff1a) shouldBe !f1.isNaN()196 f1a.fzyEqual(f1b) shouldBe !f1.isNaN()197 f1a.fzyEqual(ff1b) shouldBe !f1.isNaN()198 f1b.fzyEqual(f1) shouldBe !f1.isNaN()199 f1b.fzyEqual(ff1) shouldBe !f1.isNaN()200 ff1.equals(f1a) shouldBe !f1.isNaN()201 (ff1 == ff1a) shouldBe !f1.isNaN()...

Full Screen

Full Screen

TraceStateTest.kt

Source:TraceStateTest.kt Github

copy

Full Screen

...54 shouldThrowAny { firstTraceState["dog"] }55 }56 @Test57 fun sizeAndEmpty() {58 TraceState.default.size() shouldBeExactly 059 TraceState.default.isEmpty.shouldBeTrue()60 firstTraceState.size() shouldBeExactly 161 firstTraceState.isEmpty.shouldBeFalse()62 multiValueTraceState.size() shouldBeExactly 263 multiValueTraceState.isEmpty.shouldBeFalse()64 }65 @Test66 fun forEach() {67 val entries: MutableMap<String, String> = mutableMapOf()68 firstTraceState.forEach(entries::put)69 entries shouldContainExactly mapOf(FIRST_KEY to FIRST_VALUE)70 entries.clear()71 secondTraceState.forEach(entries::put)72 entries shouldContainExactly mapOf(SECOND_KEY to SECOND_VALUE)73 entries.clear()74 multiValueTraceState.forEach(entries::put)75 // Reverse order of input.76 entries shouldContainExactly mapOf(SECOND_KEY to SECOND_VALUE, FIRST_KEY to FIRST_VALUE)77 }78 @Test79 fun asMap() {80 firstTraceState.asMap() shouldContainExactly mapOf(FIRST_KEY to FIRST_VALUE)81 secondTraceState.asMap() shouldContainExactly mapOf(SECOND_KEY to SECOND_VALUE)82 // Reverse order of input.83 multiValueTraceState.asMap() shouldContainExactly84 mapOf(SECOND_KEY to SECOND_VALUE, FIRST_KEY to FIRST_VALUE)85 }86 @Test87 fun disallowsEmptyKey() {88 TraceState.builder().put("", FIRST_VALUE).build() shouldBe TraceState.default89 }90 @Test91 fun invalidFirstKeyCharacter() {92 TraceState.builder().put("${'$'}_key", FIRST_VALUE).build() shouldBe TraceState.default93 }94 @Test95 fun firstKeyCharacterDigitIsAllowed() {96 // note: a digit is only allowed if the key is in the tenant format (with an '@')97 val result = TraceState.builder().put("1@tenant", FIRST_VALUE).build()98 result["1@tenant"] shouldBe FIRST_VALUE99 }100 @Test101 fun testValidLongTenantId() {102 val result = TraceState.builder().put("12345678901234567890@nr", FIRST_VALUE).build()103 result["12345678901234567890@nr"] shouldBe FIRST_VALUE104 }105 @Test106 fun invalidKeyCharacters() {107 TraceState.builder().put("kEy_1", FIRST_VALUE).build() shouldBe TraceState.default108 }109 @Test110 fun testValidAtSignVendorNamePrefix() {111 val result = TraceState.builder().put("1@nr", FIRST_VALUE).build()112 result["1@nr"] shouldBe FIRST_VALUE113 }114 @Test115 fun testVendorIdLongerThan13Characters() {116 TraceState.builder().put("1@nrabcdefghijkl", FIRST_VALUE).build() shouldBe117 TraceState.default118 }119 @Test120 fun testVendorIdLongerThan13Characters_longTenantId() {121 TraceState.builder()122 .put("12345678901234567890@nrabcdefghijkl", FIRST_VALUE)123 .build() shouldBe TraceState.default124 }125 @Test126 fun tenantIdLongerThan240Characters() {127 val tenantId = (0..240).map { 'a' }.toCharArray().concatToString()128 TraceState.builder().put("$tenantId@nrabcdefghijkl", FIRST_VALUE).build() shouldBe129 TraceState.default130 }131 @Test132 fun testNonVendorFormatFirstKeyCharacter() {133 TraceState.builder().put("1acdfrgs", FIRST_VALUE).build() shouldBe TraceState.default134 }135 @Test136 fun testMultipleAtSignNotAllowed() {137 TraceState.builder().put("1@n@r@", FIRST_VALUE).build() shouldBe TraceState.default138 }139 @Test140 fun invalidKeySize() {141 val longKey = (0..257).map { 'a' }.toCharArray().concatToString()142 TraceState.builder().put(longKey, FIRST_VALUE).build() shouldBe TraceState.default143 }144 @Test145 fun allAllowedKeyCharacters() {146 val allowedKey =147 listOf(('a'..'z'), ('0'..'1'), listOf('_', '-', '*', '/'))148 .flatten()149 .toCharArray()150 .concatToString()151 val result = TraceState.builder().put(allowedKey, FIRST_VALUE).build()152 result[allowedKey] shouldBe FIRST_VALUE153 }154 @Test155 fun invalidValueSize() {156 val longValue = (0..257).map { 'a' }.toCharArray().concatToString()157 TraceState.builder().put(FIRST_KEY, longValue).build() shouldBe TraceState.default158 }159 @Test160 fun allAllowedValueCharacters() {161 val allowedValue =162 (' '..'~').filter { c -> c != ',' && c != '=' }.toCharArray().concatToString()163 val result = TraceState.builder().put(FIRST_KEY, allowedValue).build()164 result[FIRST_KEY] shouldBe allowedValue165 }166 @Test167 fun invalidValues() {168 TraceState.builder().put("foo", "bar,").build() shouldBe TraceState.default169 TraceState.builder().put("foo", "bar ").build() shouldBe TraceState.default170 TraceState.builder().put("foo", "bar=").build() shouldBe TraceState.default171 TraceState.builder().put("foo", "bar\u0019").build() shouldBe TraceState.default172 TraceState.builder().put("foo", "bar\u007F").build() shouldBe TraceState.default173 }174 @Test175 fun addEntry() {176 firstTraceState.toBuilder().put(SECOND_KEY, SECOND_VALUE).build() shouldBe177 multiValueTraceState178 }179 @Test180 fun updateEntry() {181 firstTraceState.toBuilder().put(FIRST_KEY, SECOND_VALUE).build().get(FIRST_KEY) shouldBe182 SECOND_VALUE183 val updatedMultiValueTraceState =184 multiValueTraceState.toBuilder().put(FIRST_KEY, SECOND_VALUE).build()185 updatedMultiValueTraceState[FIRST_KEY] shouldBe SECOND_VALUE186 updatedMultiValueTraceState[SECOND_KEY] shouldBe SECOND_VALUE187 }188 @Test189 fun addAndUpdateEntry() {190 val state =191 firstTraceState192 .toBuilder()193 .put(FIRST_KEY, SECOND_VALUE) // update the existing entry194 .put(SECOND_KEY, FIRST_VALUE) // add a new entry195 .build() as196 ArrayBasedTraceState197 state.entries shouldContainInOrder listOf(SECOND_KEY, FIRST_VALUE, FIRST_KEY, SECOND_VALUE)198 }199 @Test200 fun addSameKey() {201 val state =202 TraceState.builder()203 .put(FIRST_KEY, SECOND_VALUE) // update the existing entry204 .put(FIRST_KEY, FIRST_VALUE) // add a new entry205 .build() as206 ArrayBasedTraceState207 state.entries shouldContainInOrder listOf(FIRST_KEY, FIRST_VALUE)208 }209 @Test210 fun remove() {211 multiValueTraceState.toBuilder().remove(SECOND_KEY).build() shouldBe firstTraceState212 }213 @Test214 fun addAndRemoveEntry() {215 TraceState.builder()216 .put(FIRST_KEY, SECOND_VALUE) // update the existing entry217 .remove(FIRST_KEY) // add a new entry218 .build() shouldBe TraceState.default219 }220 @Test221 fun traceState_EqualsAndHashCode() {222 val tester = EqualsTester()223 tester.addEqualityGroup(224 TraceState.default,225 TraceState.default,226 TraceState.default.toBuilder().build(),227 TraceState.builder().build()228 )229 tester.addEqualityGroup(230 firstTraceState,231 TraceState.builder().put(FIRST_KEY, FIRST_VALUE).build()232 )233 tester.addEqualityGroup(234 secondTraceState,235 TraceState.builder().put(SECOND_KEY, SECOND_VALUE).build()236 )237 shouldNotThrowAny { tester.testEquals() }238 }239 @Test240 fun traceState_ToString() {241 TraceState.default.toString() shouldBe "ArrayBasedTraceState(entries=[])"242 }243}...

Full Screen

Full Screen

predef-test.kt

Source:predef-test.kt Github

copy

Full Screen

1package arrow.fx.coroutines2import arrow.core.Either3import arrow.core.Validated4import arrow.core.ValidatedNel5import arrow.core.identity6import arrow.core.invalid7import arrow.core.invalidNel8import arrow.core.left9import arrow.core.right10import arrow.core.valid11import arrow.core.validNel12import io.kotest.assertions.fail13import io.kotest.matchers.Matcher14import io.kotest.matchers.MatcherResult15import io.kotest.matchers.equalityMatcher16import io.kotest.matchers.types.shouldBeInstanceOf17import io.kotest.property.Arb18import io.kotest.property.arbitrary.bind19import io.kotest.property.arbitrary.char20import io.kotest.property.arbitrary.choice21import io.kotest.property.arbitrary.constant22import io.kotest.property.arbitrary.int23import io.kotest.property.arbitrary.long24import io.kotest.property.arbitrary.map25import io.kotest.property.arbitrary.string26import kotlinx.atomicfu.atomic27import kotlinx.coroutines.Dispatchers28import java.io.ByteArrayOutputStream29import java.io.OutputStream30import java.io.PrintStream31import java.nio.charset.StandardCharsets32import java.util.concurrent.ThreadFactory33import kotlin.coroutines.Continuation34import kotlin.coroutines.CoroutineContext35import kotlin.coroutines.EmptyCoroutineContext36import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED37import kotlin.coroutines.intrinsics.intercepted38import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn39import kotlin.coroutines.resume40import kotlin.coroutines.startCoroutine41data class SideEffect(var counter: Int = 0) {42 fun increment() {43 counter++44 }45}46val singleThreadName = "single"47val single = Resource.singleThreadContext(singleThreadName)48val threadName: suspend () -> String =49 { Thread.currentThread().name }50class NamedThreadFactory(private val mkName: (Int) -> String) : ThreadFactory {51 private val count = atomic(0)52 override fun newThread(r: Runnable): Thread =53 Thread(r, mkName(count.value))54 .apply { isDaemon = true }55}56fun unsafeEquals(other: CancelToken): Matcher<CancelToken> = object : Matcher<CancelToken> {57 val env = Environment(EmptyCoroutineContext)58 override fun test(value: CancelToken): MatcherResult {59 val r1 = env.unsafeRunSync { value.cancel.invoke() }60 val r2 = env.unsafeRunSync { other.cancel.invoke() }61 return MatcherResult(r1 == r2, "Expected: $r2 but found: $r1", "$r2 and $r1 should be equal")62 }63}64suspend fun assertCancellable(f: suspend () -> Unit): Unit {65 val p = Promise<ExitCase>()66 val start = Promise<Unit>()67 val fiber = ForkAndForget {68 guaranteeCase(69 fa = {70 start.complete(Unit)71 f()72 },73 finalizer = { ex -> p.complete(ex) }74 )75 }76 start.get()77 fiber.cancel()78 p.get().shouldBeInstanceOf<ExitCase.Cancelled>()79}80/**81 * Catches `System.err` output, for testing purposes.82 */83fun catchSystemErr(thunk: () -> Unit): String {84 val outStream = ByteArrayOutputStream()85 catchSystemErrInto(outStream, thunk)86 return String(outStream.toByteArray(), StandardCharsets.UTF_8)87}88/**89 * Catches `System.err` output into `outStream`, for testing purposes.90 */91@Synchronized92fun <A> catchSystemErrInto(outStream: OutputStream, thunk: () -> A): A {93 val oldErr = System.err94 val fakeErr = PrintStream(outStream)95 System.setErr(fakeErr)96 return try {97 thunk()98 } finally {99 System.setErr(oldErr)100 fakeErr.close()101 }102}103fun Arb.Companion.throwable(): Arb<Throwable> =104 Arb.string().map(::RuntimeException)105fun <L, R> Arb.Companion.either(left: Arb<L>, right: Arb<R>): Arb<Either<L, R>> {106 val failure: Arb<Either<L, R>> = left.map { l -> l.left() }107 val success: Arb<Either<L, R>> = right.map { r -> r.right() }108 return Arb.choice(failure, success)109}110fun <L, R> Arb.Companion.validated(left: Arb<L>, right: Arb<R>): Arb<Validated<L, R>> {111 val failure: Arb<Validated<L, R>> = left.map { l -> l.invalid() }112 val success: Arb<Validated<L, R>> = right.map { r -> r.valid() }113 return Arb.choice(failure, success)114}115fun <L, R> Arb.Companion.validatedNel(left: Arb<L>, right: Arb<R>): Arb<ValidatedNel<L, R>> {116 val failure: Arb<ValidatedNel<L, R>> = left.map { l -> l.invalidNel() }117 val success: Arb<ValidatedNel<L, R>> = right.map { r -> r.validNel() }118 return Arb.choice(failure, success)119}120fun Arb.Companion.intRange(min: Int = Int.MIN_VALUE, max: Int = Int.MAX_VALUE): Arb<IntRange> =121 Arb.bind(Arb.int(min, max), Arb.int(min, max)) { a, b ->122 if (a < b) a..b else b..a123 }124fun Arb.Companion.longRange(min: Long = Long.MIN_VALUE, max: Long = Long.MAX_VALUE): Arb<LongRange> =125 Arb.bind(Arb.long(min, max), Arb.long(min, max)) { a, b ->126 if (a < b) a..b else b..a127 }128fun Arb.Companion.charRange(): Arb<CharRange> =129 Arb.bind(Arb.char(), Arb.char()) { a, b ->130 if (a < b) a..b else b..a131 }132fun <O> Arb.Companion.function(arb: Arb<O>): Arb<() -> O> =133 arb.map { { it } }134fun Arb.Companion.unit(): Arb<Unit> =135 Arb.constant(Unit)136fun <A, B> Arb.Companion.functionAToB(arb: Arb<B>): Arb<(A) -> B> =137 arb.map { b: B -> { _: A -> b } }138fun <A> Arb.Companion.nullable(arb: Arb<A>): Arb<A?> =139 Arb.Companion.choice(arb, arb.map { null })140/** Useful for testing success & error scenarios with an `Either` generator **/141fun <A> Either<Throwable, A>.rethrow(): A =142 fold({ throw it }, ::identity)143fun <A> Result<A>.toEither(): Either<Throwable, A> =144 fold({ a -> Either.Right(a) }, { e -> Either.Left(e) })145suspend fun Throwable.suspend(): Nothing =146 suspendCoroutineUninterceptedOrReturn { cont ->147 suspend { throw this }.startCoroutine(148 Continuation(Dispatchers.Default) {149 cont.intercepted().resumeWith(it)150 }151 )152 COROUTINE_SUSPENDED153 }154suspend fun <A> A.suspend(): A =155 suspendCoroutineUninterceptedOrReturn { cont ->156 suspend { this }.startCoroutine(157 Continuation(Dispatchers.Default) {158 cont.intercepted().resumeWith(it)159 }160 )161 COROUTINE_SUSPENDED162 }163fun <A> A.suspended(): suspend () -> A =164 suspend { suspend() }165/**166 * Example usage:167 * ```kotlin168 * val exception = assertThrows<IllegalArgumentException> {169 * throw IllegalArgumentException("Talk to a duck")170 * }171 * assertEquals("Talk to a duck", exception.message)172 * ```173 * @see Assertions.assertThrows174 */175inline fun <A> assertThrowable(executable: () -> A): Throwable {176 val a = try {177 executable.invoke()178 } catch (e: Throwable) {179 e180 }181 return if (a is Throwable) a else fail("Expected an exception but found: $a")182}183suspend fun CoroutineContext.shift(): Unit =184 suspendCoroutineUninterceptedOrReturn { cont ->185 suspend { this }.startCoroutine(186 Continuation(this) {187 cont.resume(Unit)188 }189 )190 COROUTINE_SUSPENDED191 }192fun leftException(e: Throwable): Matcher<Either<Throwable, *>> =193 object : Matcher<Either<Throwable, *>> {194 override fun test(value: Either<Throwable, *>): MatcherResult =195 when (value) {196 is Either.Left -> when {197 value.a::class != e::class -> MatcherResult(198 false,199 "Expected exception of type ${e::class} but found ${value.a::class}",200 "Should not be exception of type ${e::class}"201 )202 value.a.message != e.message -> MatcherResult(203 false,204 "Expected exception with message ${e.message} but found ${value.a.message}",205 "Should not be exception with message ${e.message}"206 )207 else -> MatcherResult(208 true,209 "Expected exception of type ${e::class} and found ${value.a::class}",210 "Expected exception of type ${e::class} and found ${value.a::class}"211 )212 }213 is Either.Right -> MatcherResult(214 false,215 "Expected Either.Left with exception of type ${e::class} and found Right with ${value.b}",216 "Should not be Either.Left with exception"217 )218 }219 }220fun <A> either(e: Either<Throwable, A>): Matcher<Either<Throwable, A>> =221 object : Matcher<Either<Throwable, A>> {222 override fun test(value: Either<Throwable, A>): MatcherResult =223 when (value) {224 is Either.Left -> when {225 value.a::class != (e.swap().orNull() ?: Int)::class -> MatcherResult(226 false,227 "Expected $e but found $value",228 "Should not be $e"229 )230 value.a.message != (e.swap().orNull()?.message ?: -1) -> MatcherResult(231 false,232 "Expected $e but found $value",233 "Should not be $e"234 )235 else -> MatcherResult(236 true,237 "Expected exception of type ${e::class} and found ${value.a::class}",238 "Expected exception of type ${e::class} and found ${value.a::class}"239 )240 }241 is Either.Right -> equalityMatcher(e).test(value)242 }243 }...

Full Screen

Full Screen

FzyDoubleTest.kt

Source:FzyDoubleTest.kt Github

copy

Full Screen

...10import io.kotest.property.arbitrary.arbitrary11import io.kotest.property.arbitrary.double12import io.kotest.property.arbitrary.numericDoubles13class FzyDoubleTest : FunSpec({14 val alterDoubleTol = 2.0 * defaultDoubleTol15 val fzyDoubleDefaultArb: Arb<FzyDouble> = arbitrary { rs: RandomSource ->16 FzyDouble(rs.random.nextDouble())17 }18 val fzyDoubleAlterArb: Arb<FzyDouble> = arbitrary { rs: RandomSource ->19 FzyDouble(rs.random.nextDouble(), alterDoubleTol)20 }21 beforeTest {}22 beforeEach {}23 test("equals default") {24 checkAll(fzyDoubleDefaultArb) { fzd1 ->25 val tt = fzd1.tol26 val halfTt = fzd1.tol / 2.027 val twiceTt = fzd1.tol * 2.028 (fzd1 == fzd1) shouldBe true29 val aux0 = FzyDouble(fzd1.qty, fzd1.tol)30 (fzd1 == aux0) shouldBe true31 val aux1 = FzyDouble(fzd1.qty+fzd1.qty*halfTt)32 (fzd1.qty == aux1.qty) shouldBe false33 (fzd1 == aux1) shouldBe true34 (fzd1 == FzyDouble(fzd1.qty, twiceTt)) shouldBe false35 fzd1.equals(fzd1.qty) shouldBe true36 fzd1.equals(fzd1.qty+tt) shouldBe false37 fzd1.equals(fzd1.qty-tt) shouldBe false38 fzd1.equals(fzd1.qty.toFloat()) shouldBe false39 fzd1.equals(null) shouldBe false40 fzd1.equals("") shouldBe false41 }42 }43 test("equals alter") {44 checkAll(fzyDoubleAlterArb) { fzda1 ->45 val tt = fzda1.tol46 val halfTt = fzda1.tol / 2.047 val twiceTt = fzda1.tol * 2.048 (fzda1 == fzda1) shouldBe true49 val aux0 = FzyDouble(fzda1.qty, fzda1.tol)50 (fzda1 == aux0) shouldBe true51 val aux1 = FzyDouble(fzda1.qty+fzda1.qty*halfTt,alterDoubleTol)52 (fzda1.qty == aux1.qty) shouldBe false53 (fzda1 == aux1) shouldBe true54 (fzda1 == FzyDouble(fzda1.qty, twiceTt)) shouldBe false55 fzda1.equals(fzda1.qty) shouldBe true56 fzda1.equals(fzda1.qty+tt) shouldBe false57 fzda1.equals(fzda1.qty-tt) shouldBe false58 fzda1.equals(fzda1.qty.toFloat()) shouldBe false59 fzda1.equals(null) shouldBe false60 fzda1.equals("") shouldBe false61 }62 }63 test("equals mixed") {64 checkAll(fzyDoubleDefaultArb, fzyDoubleAlterArb) { fzd1, fzda1 ->65 fzd1.equals(fzda1) shouldBe false66 fzda1.equals(fzda1.qty) shouldBe true67 }68 }69 test("equal (zeroes)") {70 zero().equal(zero()) shouldBe true71 zero().equal(unity()) shouldBe false72 unity().equal(zero()) shouldBe false73 doubleEps.fzyEqual(zero()) shouldBe true74 zero().equals(doubleEps) shouldBe true75 }76 test("hashCode") {77 forAll<FzyDouble, FzyDouble>(PropTestConfig(iterations = 10),fzyDoubleDefaultArb,fzyDoubleDefaultArb) { fzd1, fzd2 ->78 fzd1.hashCode() == fzd1.hashCode()79 && fzd2.hashCode() == fzd2.hashCode()80 && fzd1.hashCode() != fzd2.hashCode()81 }82 }83 test("isZero") {84 FzyDouble.zero().isZero() shouldBe true85 FzyDouble.zero(alterDoubleTol).isZero() shouldBe true86 }87 test("isUnity") {88 FzyDouble.unity().isUnity() shouldBe true89 FzyDouble.unity(alterDoubleTol).isUnity() shouldBe true90 }91 test("Double.fzyEqual") {92 checkAll(Arb.numericDoubles()) { nd1 ->93 val nf1fzy = nd1.asFzyDouble()94 nd1.fzyEqual(nf1fzy) shouldBe true95 nd1.fzyEqual(nd1.asFzyDouble(alterDoubleTol)) shouldBe true96 nd1.fzyEqual(nd1, defaultDoubleTol) shouldBe true97 nd1.fzyEqual(nd1, alterDoubleTol) shouldBe true98 val tol = nf1fzy.tol99 val aux = if (nd1 == 0.0) 1.0 + tol * 20.0 else nd1 + nd1 * tol * 20.0100 val nf2 = if (nd1 != aux) aux else nd1 + 1.0101 (nd1 != nf2) shouldBe true102 nd1.fzyEqual(nf2.asFzyDouble()) shouldBe false103 nd1.fzyEqual(nf2, defaultDoubleTol) shouldBe false104 nd1.fzyEqual(nf2, alterDoubleTol) shouldBe false105 }106 }107 test("Double.fzyEqual qty pathology") {108 checkAll(Arb.double()) { nf1 ->109 val nf1fzy = nf1.asFzyDouble()110 nf1.fzyEqual(nf1fzy) shouldBe !nf1.isNaN()111 nf1.fzyEqual(nf1.asFzyDouble(alterDoubleTol)) shouldBe !nf1.isNaN()112 nf1.fzyEqual(nf1, defaultDoubleTol) shouldBe !nf1.isNaN()113 nf1.fzyEqual(nf1, alterDoubleTol) shouldBe !nf1.isNaN()114 nf1fzy.fzyEqual(nf1) shouldBe !nf1.isNaN()115 nf1fzy.fzyEqual(nf1fzy) shouldBe !nf1.isNaN()116 }117 }118 test("Double.fzyEqual tol pathology") {119 checkAll(Arb.numericDoubles(), Arb.double()) { nfQty, nfTol ->120 val tol = Math.abs(nfTol)121 val nf1fzy = FzyDouble(nfQty, tol, defeatOk = true)122 nfQty.fzyEqual(nf1fzy) shouldBe !tol.isNaN()123 nfQty.fzyEqual(nfQty.asFzyDouble(alterDoubleTol)) shouldBe true124 nfQty.fzyEqual(nfQty, tol) shouldBe !tol.isNaN()125 nf1fzy.fzyEqual(nfQty) shouldBe !tol.isNaN()126 nf1fzy.fzyEqual(nf1fzy) shouldBe !tol.isNaN()...

Full Screen

Full Screen

FzyFloatTest.kt

Source:FzyFloatTest.kt Github

copy

Full Screen

...10import io.kotest.property.arbitrary.arbitrary11import io.kotest.property.arbitrary.float12import io.kotest.property.arbitrary.numericFloats13class FzyFloatTest : FunSpec({14 val alterFloatTol = 2.0f * defaultFloatTol15 val fzyFloatDefaultArb: Arb<FzyFloat> = arbitrary { rs: RandomSource ->16 FzyFloat(rs.random.nextFloat())17 }18 val fzyFloatAlterArb: Arb<FzyFloat> = arbitrary { rs: RandomSource ->19 FzyFloat(rs.random.nextFloat(), alterFloatTol)20 }21 beforeTest {}22 beforeEach {}23 test("equals default") {24 checkAll(fzyFloatDefaultArb) { fzf1 ->25 val tt = fzf1.tol26 val halfTt = fzf1.tol / 2.0f27 val twiceTt = fzf1.tol * 2.0f28 (fzf1 == fzf1) shouldBe true29 val aux0 = FzyFloat(fzf1.qty,fzf1.tol)30 (fzf1 == aux0) shouldBe true31 val aux1 = FzyFloat(fzf1.qty+fzf1.qty*halfTt)32 (fzf1.qty == aux1.qty) shouldBe false33 (fzf1 == aux1) shouldBe true34 (fzf1 == FzyFloat(fzf1.qty, twiceTt)) shouldBe false35 fzf1.equals(fzf1.qty) shouldBe true36 fzf1.equals(fzf1.qty+tt) shouldBe false37 fzf1.equals(fzf1.qty-tt) shouldBe false38 fzf1.equals(fzf1.qty.toDouble()) shouldBe false39 fzf1.equals(null) shouldBe false40 fzf1.equals("") shouldBe false41 }42 }43 test("equals alter") {44 checkAll(fzyFloatAlterArb) { fzfa1 ->45 val tt = fzfa1.tol46 val halfTt = fzfa1.tol / 2.0f47 val twiceTt = fzfa1.tol * 2.0f48 (fzfa1 == fzfa1) shouldBe true49 val aux0 = FzyFloat(fzfa1.qty,fzfa1.tol)50 (fzfa1 == aux0) shouldBe true51 val aux1 = FzyFloat(fzfa1.qty+fzfa1.qty*halfTt,alterFloatTol)52 (fzfa1.qty == aux1.qty) shouldBe false53 (fzfa1 == aux1) shouldBe true54 (fzfa1 == FzyFloat(fzfa1.qty, twiceTt)) shouldBe false55 fzfa1.equals(fzfa1.qty) shouldBe true56 fzfa1.equals(fzfa1.qty+tt) shouldBe false57 fzfa1.equals(fzfa1.qty-tt) shouldBe false58 fzfa1.equals(fzfa1.qty.toDouble()) shouldBe false59 fzfa1.equals(null) shouldBe false60 fzfa1.equals("") shouldBe false61 }62 }63 test("equals mixed") {64 checkAll(fzyFloatDefaultArb, fzyFloatAlterArb) { fzf1, fzfa1 ->65 (fzf1 == fzfa1) shouldBe false66 fzfa1.equals(fzfa1.qty) shouldBe true67 }68 }69 test("equal (zeroes)") {70 zero().equal(zero()) shouldBe true71 zero().equal(unity()) shouldBe false72 unity().equal(zero()) shouldBe false73 floatEps.fzyEqual(zero()) shouldBe true74 zero().equals(floatEps) shouldBe true75 }76 test("hashCode") {77 forAll<FzyFloat, FzyFloat>(PropTestConfig(iterations = 10),fzyFloatDefaultArb,fzyFloatDefaultArb) { fzf1, fzf2 ->78 fzf1.hashCode() == fzf1.hashCode()79 && fzf2.hashCode() == fzf2.hashCode()80 && fzf1.hashCode() != fzf2.hashCode()81 }82 }83 test("isZero") {84 FzyFloat.zero().isZero() shouldBe true85 FzyFloat.zero(alterFloatTol).isZero() shouldBe true86 }87 test("isUnity") {88 FzyFloat.unity().isUnity() shouldBe true89 FzyFloat.unity(alterFloatTol).isUnity() shouldBe true90 }91 test("Float.fzyEqual") {92 checkAll(Arb.numericFloats()) { nf1 ->93 val nf1fzy = nf1.asFzyFloat()94 nf1.fzyEqual(nf1fzy) shouldBe true95 nf1.fzyEqual(nf1.asFzyFloat(alterFloatTol)) shouldBe true96 nf1.fzyEqual(nf1, defaultFloatTol) shouldBe true97 nf1.fzyEqual(nf1, alterFloatTol) shouldBe true98 val tol = nf1fzy.tol99 val aux = if (nf1 == 0.0f) 1.0f + tol * 20.0f else nf1 + nf1 * tol * 20.0f100 val nf2 = if (nf1 != aux) aux else nf1 + 1.0f101 (nf1 != nf2) shouldBe true102 nf1.fzyEqual(nf2.asFzyFloat()) shouldBe false103 nf1.fzyEqual(nf2, defaultFloatTol) shouldBe false104 nf1.fzyEqual(nf2, alterFloatTol) shouldBe false105 }106 }107 test("Float.fzyEqual qty pathology") {108 checkAll(Arb.float()) { nf1 ->109 val nf1fzy = nf1.asFzyFloat()110 nf1.fzyEqual(nf1fzy) shouldBe !nf1.isNaN()111 nf1.fzyEqual(nf1.asFzyFloat(alterFloatTol)) shouldBe !nf1.isNaN()112 nf1.fzyEqual(nf1, defaultFloatTol) shouldBe !nf1.isNaN()113 nf1.fzyEqual(nf1, alterFloatTol) shouldBe !nf1.isNaN()114 nf1fzy.fzyEqual(nf1) shouldBe !nf1.isNaN()115 nf1fzy.fzyEqual(nf1fzy) shouldBe !nf1.isNaN()116 }117 }118 test("Float.fzyEqual tol pathology") {119 checkAll(Arb.numericFloats(), Arb.float()) { nfQty, nfTol ->120 val tol = Math.abs(nfTol)121 val nf1fzy = FzyFloat(nfQty, tol, defeatOk = true)122 nfQty.fzyEqual(nf1fzy) shouldBe !tol.isNaN()123 nfQty.fzyEqual(nfQty.asFzyFloat(alterFloatTol)) shouldBe true124 nfQty.fzyEqual(nfQty, tol) shouldBe !tol.isNaN()125 nf1fzy.fzyEqual(nfQty) shouldBe !tol.isNaN()126 nf1fzy.fzyEqual(nf1fzy) shouldBe !tol.isNaN()...

Full Screen

Full Screen

DomainEventSpec.kt

Source:DomainEventSpec.kt Github

copy

Full Screen

...37 val domainEvents = List(100) {38 createDomainEvent()39 }.exhaustive()40 describe("constructor()") {41 it("should initialize an eventId by default value when passed null") {42 domainEvents.checkAll { domainEvent ->43 domainEvent.eventId should beValidUUIDString<String>()44 }45 }46 it("should initialize an occurredOn by default value when passed null") {47 domainEvents.checkAll { domainEvent ->48 domainEvent.occurredOn should beValidISODateTimeString<String>()49 }50 }51 }52 describe("equals()") {53 it("should be able equivalence comparisons") {54 domainEvents.checkAll { domainEvent ->55 val nullObject = null56 (domainEvent == domainEvent) shouldBe true57 (domainEvent == nullObject) shouldBe false58 (domainEvent.equals(object {})) shouldBe false59 with(domainEvent) {60 val clone = createDomainEvent(aggregateId, eventId, occurredOn)...

Full Screen

Full Screen

contain.kt

Source:contain.kt Github

copy

Full Screen

...5import io.kotest.matchers.MatcherResult6import io.kotest.matchers.should7import io.kotest.matchers.shouldNot8// Infix9infix fun <T> Iterable<T>.shouldNotContain(t: T): Iterable<T> = shouldNotContain(t, Equality.default())10infix fun <T> Array<T>.shouldNotContain(t: T): Array<T> = shouldNotContain(t, Equality.default())11infix fun <T> Iterable<T>.shouldContain(t: T): Iterable<T> = shouldContain(t, Equality.default())12infix fun <T> Array<T>.shouldContain(t: T): Array<T> = shouldContain(t, Equality.default())13// Should not14fun <T> Iterable<T>.shouldNotContain(t: T, comparator: Equality<T>): Iterable<T> = apply {15 toList() shouldNot contain(t, comparator)16}17fun <T> Array<T>.shouldNotContain(t: T, comparator: Equality<T>): Array<T> = apply {18 asList().shouldNotContain(t, comparator)19}20// Should21fun <T> Iterable<T>.shouldContain(t: T, comparator: Equality<T>): Iterable<T> = apply {22 toList() should contain(t, comparator)23}24fun <T> Array<T>.shouldContain(t: T, comparator: Equality<T>): Array<T> = apply {25 asList().shouldContain(t, comparator)26}27// Matcher28fun <T, C : Collection<T>> contain(t: T, verifier: Equality<T> = Equality.default()) = object : Matcher<C> {29 override fun test(value: C) = MatcherResult(30 value.any { verifier.verify(it, t).areEqual() },31 {32 "Collection should contain element ${t.print().value} based on ${verifier.name()}; " +33 "but the collection is ${value.print().value}"34 },35 { "Collection should not contain element ${t.print().value} based on ${verifier.name()}" }36 )37}...

Full Screen

Full Screen

default

Using AI Code Generation

copy

Full Screen

1+import io.kotest.assertions.Assertion2+import io.kotest.assertions.assertionCounter3+import io.kotest.assertions.failure4+import io.kotest.assertions.show.show5+import io.kotest.assertions.throwables.shouldThrow6+import io.kotest.assertions.throwables.shouldThrowAny7+import io.kotest.assertions.throwables.shouldThrowExactly8+import io.kotest.assertions.throwables.shouldThrowUnit9+import io.kotest.core.test.AssertionMode10+import io.kotest.core.test.TestCase11+import io.kotest.core.test.TestContext12+import io.kotest.core.test.TestType13+import io.kotest.core.test.createTestName14+import io.kotest.core.test.createTestNameOrNull15+import io.kotest.core.test.enabledIf16+import io.kotest.core.test.invoke17+import io.kotest.core.test.registerTestCase18+import io.kotest.core.test.set19+import io.kotest.core.test.test20+import io.kotest.core.test.toTestCase21+import io.kotest.core.test.toTestType22+import io.kotest.core.test.withDefaultTestConfig23+import io.kotest.core.test.withTestName24+import io.kotest.mpp.bestName25+import io.kotest.mpp.log26+import kotlin.reflect.KClass27+ * test("name").config(...) {28+ * }29+ * xtest("name").config(...) {30+ * }31+ * test("name").config(...) {32+ * }33+ * xtest("name").config(...) {34+ * }35+ * should("name").config(...) {36+ * }37+ * xshould("name").config(...) {38+ * }

Full Screen

Full Screen

default

Using AI Code Generation

copy

Full Screen

1class Person(val name: String, val age: Int)2val p1 = Person("sam", 30)3val p2 = Person("sam", 30)4p1.shouldBe(p2)5class Person(val name: String, val age: Int)6val p1 = Person("sam", 30)7val p2 = Person("sam", 30)8p1.shouldBe(p2, Equality<Person> { a, b -> a.name == b.name })9class Person(val name: String, val age: Int)10val p1 = Person("sam", 30)11val p2 = Person("sam", 30)12p1.shouldBe(p2, { a, b -> a.name == b.name })13class Person(val name: String, val age: Int)14val p1 = Person("sam", 30)15val p2 = Person("sam", 30)16p1.shouldBe(p2, { a, b -> a.name == b.name })17class Person(val name: String, val age: Int)18val p1 = Person("sam", 30)19val p2 = Person("sam", 30)20p1.shouldBe(p2, { a, b -> a.name == b.name })21class Person(val name: String, val age: Int)22val p1 = Person("sam", 30)23val p2 = Person("sam", 30)24p1.shouldBe(p2, { a, b -> a.name == b.name })25class Person(val name: String, val age: Int)26val p1 = Person("sam", 30)27val p2 = Person("sam", 30)28p1.shouldBe(p2, { a, b -> a.name == b.name })29class Person(val name: String, val age: Int)30val p1 = Person("sam", 30)31val p2 = Person("sam

Full Screen

Full Screen

default

Using AI Code Generation

copy

Full Screen

1val equality = Equality.default()2val list = listOf(1, 2, 3)3val list2 = listOf(1, 2, 3)4val list3 = listOf(3, 2, 1)5val equality = Equality { a, b -> a == b }6val list = listOf(1, 2, 3)7val list2 = listOf(1, 2, 3)8val list3 = listOf(3, 2, 1)9val equality = Equality { a, b -> a == b }10val list = listOf(1, 2, 3)11val list2 = listOf(1, 2, 3)12val list3 = listOf(3, 2, 1)13val equality = Equality { a, b -> a == b }14val list = listOf(1, 2, 3)15val list2 = listOf(1, 2, 3)16val list3 = listOf(3, 2, 1)17val equality = Equality { a, b ->

Full Screen

Full Screen

default

Using AI Code Generation

copy

Full Screen

1 assertEquals(1, 1)2 assertEquals("hello", "hello")3 assertEquals(null, null)4 assertEquals(listOf(1, 2, 3), listOf(1, 2, 3))5 assertEquals(1, 1, "message")6 assertEquals("hello", "hello", "message")7 assertEquals(null, null, "message")8 assertEquals(listOf(1, 2, 3), listOf(1, 2, 3), "message")9 assertEquals(1, 1, Equality.defaultEquality())10 assertEquals("hello", "hello", Equality.defaultEquality())11 assertEquals(null, null, Equality.defaultEquality())12 assertEquals(listOf(1, 2, 3), listOf(1, 2, 3), Equality.defaultEquality())13 assertEquals(1, 1, "message", Equality.defaultEquality())14 assertEquals("hello", "hello", "message", Equality.defaultEquality())15 assertEquals(null, null, "message", Equality.defaultEquality())16 assertEquals(listOf(1, 2, 3), listOf(1, 2, 3), "message", Equality.defaultEquality())

Full Screen

Full Screen

default

Using AI Code Generation

copy

Full Screen

1 data class Person(val name: String, val age: Int) : Equality by Equality.default() {2 override fun toString(): String = "$name is $age years old"3 }4 class Person(val name: String, val age: Int) : Equality by eq()5 data class Person(val name: String, val age: Int) : Equality by eq()6 class Person(val name: String, val age: Int) : Equality by eq()7 data class Person(val name: String, val age: Int) : Equality by eq()

Full Screen

Full Screen

default

Using AI Code Generation

copy

Full Screen

1 }2}3class PersonTest : FunSpec() {4 init {5 test("test equals") {6 val person1 = Person("John", 30)7 val person2 = Person("John", 30)8 val person3 = Person2("John", 30)9 val person4 = Person2("John", 30)10 }11 }12}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Equality

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful