How to use test method of io.kotest.matchers.types.hash class

Best Kotest code snippet using io.kotest.matchers.types.hash.test

ColorContainerTest.kt

Source:ColorContainerTest.kt Github

copy

Full Screen

...19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN20 * THE SOFTWARE.21 *22 */23package animatedledstrip.test.colors24import animatedledstrip.colors.*25import io.kotest.assertions.throwables.shouldThrow26import io.kotest.core.spec.style.StringSpec27import io.kotest.matchers.booleans.shouldBeFalse28import io.kotest.matchers.booleans.shouldBeTrue29import io.kotest.matchers.collections.shouldBeEmpty30import io.kotest.matchers.collections.shouldContainExactly31import io.kotest.matchers.collections.shouldExistInOrder32import io.kotest.matchers.collections.shouldStartWith33import io.kotest.matchers.shouldBe34import io.kotest.matchers.shouldNotBe35import io.kotest.matchers.types.shouldBeSameInstanceAs36import io.kotest.matchers.types.shouldNotBeSameInstanceAs37import io.kotest.property.Arb38import io.kotest.property.arbitrary.filter39import io.kotest.property.arbitrary.int40import io.kotest.property.arbitrary.list41import io.kotest.property.arbitrary.next42import io.kotest.property.checkAll43class ColorContainerTest : StringSpec(44 {45 "primary constructor" {46 checkAll<Int> { c ->47 ColorContainer(c).color shouldBe c48 }49 }50 "ColorContainer constructor" {51 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->52 val cc = ColorContainer(c.toMutableList())53 ColorContainer(cc).colors shouldBe cc.colors54 }55 }56 "RGB constructor" {57 checkAll(Arb.int(0..0xFF),58 Arb.int(0..0xFF),59 Arb.int(0..0xFF)) { r, g, b ->60 ColorContainer(Triple(r, g, b)).color shouldBe ((r shl 16) or (g shl 8) or b)61 }62 }63 "list constructor" {64 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->65 ColorContainer(c.toMutableList()).colors shouldBe c.toMutableList()66 }67 }68 "get" {69 checkAll(Arb.int(0..0xFFFFFF),70 Arb.int(0..0xFFFFFF),71 Arb.int(0..0xFFFFFF),72 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->73 val testCC = ColorContainer(c1, c2, c3, c4)74 testCC[0] shouldBe c175 testCC[0, 2] shouldBe listOf(c1, c3)76 testCC[0..2] shouldBe listOf(c1, c2, c3)77 testCC[IntRange(2, 0)] shouldBe listOf() // Test with empty IntRange78 testCC.color shouldBe c179 testCC[5] shouldBe 080 testCC[3, 5] shouldBe listOf(c4, 0)81 testCC[3..5] shouldBe listOf(c4, 0, 0)82 }83 val testCC = ColorContainer()84 testCC.color shouldBe 085 }86 "set" {87 checkAll(Arb.int(0..0xFFFFFF),88 Arb.int(0..0xFFFFFF),89 Arb.int(0..0xFFFFFF),90 Arb.int(0..0xFFFFFF),91 Arb.int(0..0xFFFFFF),92 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4, c5, c6 ->93 val testCC = ColorContainer(c1, c2, c3)94 testCC.colors.shouldContainExactly(c1, c2, c3)95 testCC[2] = c496 testCC.colors.shouldContainExactly(c1, c2, c4)97 testCC[3, 5] = c598 testCC.colors.shouldContainExactly(c1, c2, c4, c5, c5)99 testCC[3..7] = c6100 testCC.colors.shouldContainExactly(c1, c2, c4, c6, c6, c6, c6, c6)101 testCC[IntRange(5, 3)] = c1102 testCC.colors.shouldContainExactly(c1, c2, c4, c6, c6, c6, c6, c6)103 testCC += c4104 testCC.colors.shouldContainExactly(c1, c2, c4, c6, c6, c6, c6, c6, c4)105 }106 }107 "prepare" {108 val p = ColorContainer(0xFF7B51, 0xF0AF29, 0x3C538B).prepare(50)109 p.colors.shouldStartWith(0xFF7B51)110 p.colors.shouldExistInOrder({ it == 0xFF7B51 }, { it == 0xF0AF29 }, { it == 0x3C538B })111 p.originalColors.shouldContainExactly(0xFF7B51, 0xF0AF29, 0x3C538B)112 ColorContainer().prepare(5).colors.shouldContainExactly(0, 0, 0, 0, 0)113 shouldThrow<IllegalArgumentException> {114 ColorContainer(0xFF).prepare(0)115 }116 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..100)) { c ->117 ColorContainer(c.toMutableList()).prepare(500)118 }119 }120 "string" {121 ColorContainer(0xFF3B82).toString() shouldBe "[ff3b82]"122 ColorContainer(0xFF7B50, 0xFFFFFF).toString() shouldBe "[ff7b50, ffffff]"123 ColorContainer().toString() shouldBe "[]"124 }125 "toInt" {126 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..100)) { c ->127 ColorContainer(c.toMutableList()).toInt() shouldBe c.first()128 }129 }130 "toRGB" {131 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..100)) { c ->132 ColorContainer(c.toMutableList()).toRGB() shouldBe Triple(c.first().r, c.first().g, c.first().b)133 ColorContainer(c.toMutableList()).toTriple() shouldBe Triple(c.first().r, c.first().g, c.first().b)134 }135 }136 "toColorContainer" {137 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->138 val testCC = ColorContainer(c.toMutableList())139 testCC.toColorContainer() shouldBeSameInstanceAs testCC140 }141 }142 "equality" {143 checkAll(50, Arb.int(0..0xFFFFFF)) { c ->144 val testCC = ColorContainer(c)145 testCC shouldBe ColorContainer(c)146 testCC.hashCode() shouldBe ColorContainer(c).hashCode()147 testCC shouldBe c148 checkAll(10, Arb.int(0..0xFFFFFF).filter { it != c }) { c2 ->149 testCC shouldNotBe ColorContainer(c2)150 testCC.hashCode() shouldNotBe ColorContainer(c2).hashCode()151 testCC shouldNotBe c2152 }153 checkAll(10, Arb.list(Arb.int(0..0xFFFFFF), 2..100)) { c3 ->154 testCC shouldNotBe ColorContainer(c3.toMutableList())155 }156 }157 checkAll(Arb.list(Arb.int(0..0xFFFFFF)).filter { it.isNotEmpty() }) { c ->158 val testCC = ColorContainer(c.toMutableList())159 testCC shouldBe ColorContainer(c.toMutableList())160 testCC.hashCode() shouldBe ColorContainer(c.toMutableList()).hashCode()161 testCC shouldNotBe c162 testCC.hashCode() shouldBe c.hashCode()163 checkAll(50, Arb.int(1..500).filter { it != c.size }) { len ->164 testCC shouldBe ColorContainer(c.toMutableList()).prepare(len)165 testCC.hashCode() shouldNotBe ColorContainer(c.toMutableList()).prepare(len).hashCode()166 }167 checkAll(10, Arb.list(Arb.int(0..0xFFFFFF)).filter { it != c }) { c2 ->168 testCC shouldNotBe ColorContainer(c2.toMutableList())169 testCC.hashCode() shouldNotBe ColorContainer(c2.toMutableList()).hashCode()170 testCC shouldNotBe c2171 testCC.hashCode() shouldNotBe c2.hashCode()172 }173 }174 }175 "contains" {176 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->177 val testCC = ColorContainer(c.toMutableList())178 for (i in c) {179 (i in testCC).shouldBeTrue()180 }181 for (i in Arb.list(Arb.int(0..0xFFFFFF).filter { it !in c }, 10..10).next())182 (i in testCC).shouldBeFalse()183 }184 }185 "size" {186 checkAll(Arb.list(Arb.int(0..0xFFFFFF))) { c ->187 ColorContainer(c.toMutableList()).size shouldBe c.size188 }189 }190 "grayscale" {191 checkAll(Arb.int(0..0xFFFFFF),192 Arb.int(0..0xFFFFFF)) { c1, c2 ->193 val testCC = ColorContainer(c1, c2)194 testCC.grayscale() shouldBeSameInstanceAs testCC195 testCC.colors.shouldContainExactly(c1.grayscale(),196 c2.grayscale())197 }198 checkAll(Arb.int(0..0xFFFFFF),199 Arb.int(0..0xFFFFFF),200 Arb.int(0..0xFFFFFF),201 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->202 val testCC = ColorContainer(c1, c2, c3, c4)203 testCC.grayscale(0, 3) shouldBeSameInstanceAs testCC204 testCC.colors.shouldContainExactly(c1.grayscale(),205 c2,206 c3,207 c4.grayscale())208 testCC.grayscale(1, 2) shouldBeSameInstanceAs testCC209 testCC.colors.shouldContainExactly(c1.grayscale(),210 c2.grayscale(),211 c3.grayscale(),212 c4.grayscale())213 val testCC2 = ColorContainer(c1, c2, c3, c4)214 testCC2.grayscale(3, 1, 2) shouldBeSameInstanceAs testCC2215 testCC2.colors.shouldContainExactly(c1,216 c2.grayscale(),217 c3.grayscale(),218 c4.grayscale())219 val testCC3 = ColorContainer(c1, c2, c3, c4)220 testCC3.grayscale(8) shouldBeSameInstanceAs testCC3221 testCC3.colors.shouldContainExactly(c1, c2, c3, c4)222 }223 checkAll(Arb.int(0..0xFFFFFF),224 Arb.int(0..0xFFFFFF),225 Arb.int(0..0xFFFFFF),226 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->227 val testCC = ColorContainer(c1, c2, c3, c4)228 testCC.grayscale(0..2) shouldBeSameInstanceAs testCC229 testCC.colors.shouldContainExactly(c1.grayscale(),230 c2.grayscale(),231 c3.grayscale(),232 c4)233 val testCC2 = ColorContainer(c1, c2, c3, c4)234 testCC2.grayscale(0..1, 3..5) shouldBeSameInstanceAs testCC2235 testCC2.colors.shouldContainExactly(c1.grayscale(),236 c2.grayscale(),237 c3,238 c4.grayscale())239 val testCC3 = ColorContainer(c1, c2, c3, c4)240 testCC3.grayscale(IntRange(2, 0)) shouldBeSameInstanceAs testCC3241 testCC3.colors.shouldContainExactly(c1, c2, c3, c4)242 }243 }244 "grayscaled" {245 checkAll(Arb.int(0..0xFFFFFF),246 Arb.int(0..0xFFFFFF)) { c1, c2 ->247 val testCC = ColorContainer(c1, c2)248 val gTestCC1 = testCC.grayscaled()249 gTestCC1 shouldNotBeSameInstanceAs testCC250 testCC.colors.shouldContainExactly(c1, c2)251 gTestCC1.colors.shouldContainExactly(c1.grayscale(),252 c2.grayscale())253 }254 checkAll(Arb.int(0..0xFFFFFF),255 Arb.int(0..0xFFFFFF),256 Arb.int(0..0xFFFFFF),257 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->258 val testCC = ColorContainer(c1, c2, c3, c4)259 val gTestCC1 = testCC.grayscaled(0, 3)260 gTestCC1 shouldNotBeSameInstanceAs testCC261 testCC.colors.shouldContainExactly(c1, c2, c3, c4)262 gTestCC1.colors.shouldContainExactly(c1.grayscale(),263 c4.grayscale())264 val gTestCC2 = testCC.grayscaled(3, 1, 2)265 gTestCC2 shouldNotBeSameInstanceAs testCC266 testCC.colors.shouldContainExactly(c1, c2, c3, c4)267 gTestCC2.colors.shouldContainExactly(c4.grayscale(),268 c2.grayscale(),269 c3.grayscale())270 val gTestCC3 = testCC.grayscaled(8)271 gTestCC3 shouldNotBeSameInstanceAs testCC272 testCC.colors.shouldContainExactly(c1, c2, c3, c4)273 gTestCC3.colors.shouldBeEmpty()274 }275 checkAll(Arb.int(0..0xFFFFFF),276 Arb.int(0..0xFFFFFF),277 Arb.int(0..0xFFFFFF),278 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->279 val testCC = ColorContainer(c1, c2, c3, c4)280 val gTestCC1 = testCC.grayscaled(0..2)281 gTestCC1 shouldNotBeSameInstanceAs testCC282 testCC.colors.shouldContainExactly(c1, c2, c3, c4)283 gTestCC1.colors.shouldContainExactly(c1.grayscale(),284 c2.grayscale(),285 c3.grayscale())286 val gTestCC2 = testCC.grayscaled(0..1, 3..5)287 gTestCC2 shouldNotBeSameInstanceAs testCC288 testCC.colors.shouldContainExactly(c1, c2, c3, c4)289 gTestCC2.colors.shouldContainExactly(c1.grayscale(),290 c2.grayscale(),291 c4.grayscale())292 val gTestCC3 = testCC.grayscaled(IntRange(2, 0))293 gTestCC3 shouldNotBeSameInstanceAs testCC294 testCC.colors.shouldContainExactly(c1, c2, c3, c4)295 gTestCC3.colors.shouldBeEmpty()296 }297 }298 "invert" {299 checkAll(Arb.int(0..0xFFFFFF),300 Arb.int(0..0xFFFFFF)) { c1, c2 ->301 val testCC = ColorContainer(c1, c2)302 testCC.invert() shouldBeSameInstanceAs testCC303 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,304 c2.inv() and 0xFFFFFF)305 testCC.invert() shouldBeSameInstanceAs testCC306 testCC.colors.shouldContainExactly(c1, c2)307 }308 checkAll(Arb.int(0..0xFFFFFF),309 Arb.int(0..0xFFFFFF),310 Arb.int(0..0xFFFFFF),311 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->312 val testCC = ColorContainer(c1, c2, c3, c4)313 testCC.invert(0, 3) shouldBeSameInstanceAs testCC314 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,315 c2,316 c3,317 c4.inv() and 0xFFFFFF)318 testCC.invert(1, 2) shouldBeSameInstanceAs testCC319 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,320 c2.inv() and 0xFFFFFF,321 c3.inv() and 0xFFFFFF,322 c4.inv() and 0xFFFFFF)323 testCC.invert(3, 1, 2) shouldBeSameInstanceAs testCC324 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,325 c2,326 c3,327 c4)328 testCC.invert(8) shouldBeSameInstanceAs testCC329 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,330 c2,331 c3,332 c4)333 }334 checkAll(Arb.int(0..0xFFFFFF),335 Arb.int(0..0xFFFFFF),336 Arb.int(0..0xFFFFFF),337 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->338 val testCC = ColorContainer(c1, c2, c3, c4)339 testCC.invert(0..2) shouldBeSameInstanceAs testCC340 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,341 c2.inv() and 0xFFFFFF,342 c3.inv() and 0xFFFFFF,343 c4)344 testCC.invert(1..2) shouldBeSameInstanceAs testCC345 testCC.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,346 c2,347 c3,348 c4)349 testCC.invert(0..1, 3..5) shouldBeSameInstanceAs testCC350 testCC.colors.shouldContainExactly(c1,351 c2.inv() and 0xFFFFFF,352 c3,353 c4.inv() and 0xFFFFFF)354 testCC.invert(IntRange(2, 0)) shouldBeSameInstanceAs testCC355 testCC.colors.shouldContainExactly(c1,356 c2.inv() and 0xFFFFFF,357 c3,358 c4.inv() and 0xFFFFFF)359 }360 }361 "inverse" {362 checkAll(Arb.int(0..0xFFFFFF),363 Arb.int(0..0xFFFFFF)) { c1, c2 ->364 val testCC = ColorContainer(c1, c2)365 val iTestCC1 = testCC.inverse()366 iTestCC1 shouldNotBeSameInstanceAs testCC367 testCC.colors.shouldContainExactly(c1, c2)368 iTestCC1.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,369 c2.inv() and 0xFFFFFF)370 val iTestCC2 = -testCC371 iTestCC2 shouldNotBeSameInstanceAs testCC372 testCC.colors.shouldContainExactly(c1, c2)373 iTestCC2.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,374 c2.inv() and 0xFFFFFF)375 }376 checkAll(Arb.int(0..0xFFFFFF),377 Arb.int(0..0xFFFFFF),378 Arb.int(0..0xFFFFFF),379 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->380 val testCC = ColorContainer(c1, c2, c3, c4)381 val iTestCC1 = testCC.inverse(0, 3)382 iTestCC1 shouldNotBeSameInstanceAs testCC383 testCC.colors.shouldContainExactly(c1, c2, c3, c4)384 iTestCC1.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,385 c4.inv() and 0xFFFFFF)386 val iTestCC2 = testCC.inverse(3, 1, 2)387 iTestCC2 shouldNotBeSameInstanceAs testCC388 testCC.colors.shouldContainExactly(c1, c2, c3, c4)389 iTestCC2.colors.shouldContainExactly(c4.inv() and 0xFFFFFF,390 c2.inv() and 0xFFFFFF,391 c3.inv() and 0xFFFFFF)392 val iTestCC3 = testCC.inverse(8)393 iTestCC3 shouldNotBeSameInstanceAs testCC394 testCC.colors.shouldContainExactly(c1, c2, c3, c4)395 iTestCC3.colors.shouldBeEmpty()396 }397 checkAll(Arb.int(0..0xFFFFFF),398 Arb.int(0..0xFFFFFF),399 Arb.int(0..0xFFFFFF),400 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->401 val testCC = ColorContainer(c1, c2, c3, c4)402 val iTestCC1 = testCC.inverse(0..2)403 iTestCC1 shouldNotBeSameInstanceAs testCC404 testCC.colors.shouldContainExactly(c1, c2, c3, c4)405 iTestCC1.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,406 c2.inv() and 0xFFFFFF,407 c3.inv() and 0xFFFFFF)408 val iTestCC2 = testCC.inverse(0..1, 3..5)409 iTestCC2 shouldNotBeSameInstanceAs testCC410 testCC.colors.shouldContainExactly(c1, c2, c3, c4)411 iTestCC2.colors.shouldContainExactly(c1.inv() and 0xFFFFFF,412 c2.inv() and 0xFFFFFF,413 c4.inv() and 0xFFFFFF)414 val iTestCC3 = testCC.inverse(IntRange(2, 0))415 iTestCC3 shouldNotBeSameInstanceAs testCC416 testCC.colors.shouldContainExactly(c1, c2, c3, c4)417 iTestCC3.colors.shouldBeEmpty()418 }419 }420 "is empty" {421 val testCC1 = ColorContainer()422 testCC1.isEmpty().shouldBeTrue()423 testCC1.isNotEmpty().shouldBeFalse()424 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..100)) { c ->425 val testCC2 = ColorContainer(c.toMutableList())426 testCC2.isEmpty().shouldBeFalse()427 testCC2.isNotEmpty().shouldBeTrue()428 }429 }430 })...

Full Screen

Full Screen

NumVectorTest.kt

Source:NumVectorTest.kt Github

copy

Full Screen

...8import com.github.shwaka.kohomology.specific.SparseNumVectorSpaceOverF79import com.github.shwaka.kohomology.specific.SparseNumVectorSpaceOverIntRational10import com.github.shwaka.kohomology.specific.SparseNumVectorSpaceOverRational11import com.github.shwaka.kohomology.util.Sign12import io.kotest.assertions.throwables.shouldThrow13import io.kotest.core.NamedTag14import io.kotest.core.spec.style.FreeSpec15import io.kotest.core.spec.style.freeSpec16import io.kotest.matchers.booleans.shouldBeFalse17import io.kotest.matchers.booleans.shouldBeTrue18import io.kotest.matchers.maps.shouldBeEmpty19import io.kotest.matchers.nulls.shouldBeNull20import io.kotest.matchers.shouldBe21import io.kotest.matchers.shouldNotBe22import io.kotest.matchers.types.shouldBeSameInstanceAs23import io.kotest.matchers.types.shouldNotBeSameInstanceAs24val numVectorTag = NamedTag("NumVector")25val denseNumVectorTag = NamedTag("DenseNumVector")26val sparseNumVectorTag = NamedTag("SparseNumVector")27val kococoDebug = (System.getProperty("kococo.debug") != null)28fun <S : Scalar> denseNumVectorTest(numVectorSpace: DenseNumVectorSpace<S>) = freeSpec {29 "factory should return the cache if exists" {30 val field = numVectorSpace.field31 DenseNumVectorSpace.from(field) shouldBeSameInstanceAs numVectorSpace32 }33}34fun <S : Scalar> sparseNumVectorTest(numVectorSpace: SparseNumVectorSpace<S>) = freeSpec {35 "factory should return the cache if exists" {36 val field = numVectorSpace.field37 SparseNumVectorSpace.from(field) shouldBeSameInstanceAs numVectorSpace38 }39 "fromReducedValueMap should throw if zero is explicitly given (and if debug mode is enabled)".config(enabled = kococoDebug) {40 numVectorSpace.field.context.run {41 val valueMap: Map<Int, S> = mapOf(42 1 to one,43 3 to -two,44 4 to zero,45 )46 shouldThrow<IllegalArgumentException> {47 numVectorSpace.fromReducedValueMap(valueMap, 7)48 }49 }50 }51 numVectorSpace.context.run {52 "valueMap for the vector (0, 0, 0) should be empty" {53 val v = listOf(zero, zero, zero).toNumVector()54 v.valueMap.shouldBeEmpty()55 v.dim shouldBe 356 }57 "valueMap for the vector (0, 1, 0) should have size 1" {58 val v = listOf(zero, one, zero).toNumVector()59 v.valueMap.size shouldBe 160 v.dim shouldBe 361 }62 "valueMap for (1, 0) + (-1, 0) should be empty" {63 val v = listOf(one, zero).toNumVector()64 val w = listOf(-one, zero).toNumVector()65 (v + w).valueMap.shouldBeEmpty()66 }67 "valueMap for (2, 1) * 0 should be empty" {68 val v = listOf(two, one).toNumVector()69 (v * zero).valueMap.shouldBeEmpty()70 }71 }72}73fun <S : Scalar, V : NumVector<S>> numVectorTest(numVectorSpace: NumVectorSpace<S, V>) = freeSpec {74 numVectorSpace.context.run {75 "numVectors with same values should have the same hashCode" {76 val v1 = listOf(one, two).toNumVector()77 val v2 = listOf(one, two).toNumVector()78 v1 shouldNotBeSameInstanceAs v279 v1.hashCode() shouldBe v2.hashCode()80 }81 "(0, 1) + (0, 1) should be (0, 2)" {82 val v = listOf(zero, one).toNumVector()83 val w = listOf(zero, two).toNumVector()84 (v + v) shouldBe w85 }86 "(2, 0) + (-2, 0) should be (0, 0)" {87 val v = listOf(two, zero).toNumVector()88 val w = listOf(-two, zero).toNumVector()89 (v + w) shouldBe numVectorSpace.getZero(2)90 }91 "(-1, 0) - (-1, 0) should be (0, 0)" {92 val v = listOf(-one, zero).toNumVector()93 (v - v) shouldBe numVectorSpace.getZero(2)94 }95 "(1, 0) * 2 should be (2, 0)" {96 val v = listOf(one, zero).toNumVector()97 val w = listOf(two, zero).toNumVector()98 (v * two) shouldBe w99 (v * 2) shouldBe w100 }101 "2 * (1, 0) should be (2, 0)" {102 val v = listOf(one, zero).toNumVector()103 val w = listOf(two, zero).toNumVector()104 (two * v) shouldBe w105 (2 * v) shouldBe w106 }107 "-(1, -2, 0) should be (-1, 2, 0)" {108 val v = listOf(one, -two, zero).toNumVector()109 (-v) shouldBe listOf(-one, two, zero).toNumVector()110 }111 "multiplication with Sign" {112 val v = listOf(one, -two, zero).toNumVector()113 (v * Sign.PLUS) shouldBe v114 (Sign.PLUS * v) shouldBe v115 (v * Sign.MINUS) shouldBe -v116 (Sign.MINUS * v) shouldBe -v117 }118 "(1, 0).dim should be 2" {119 val v = listOf(one, zero).toNumVector()120 v.dim shouldBe 2121 }122 "vectorSpace.getZero(3) should be (0, 0, 0)" {123 val v = numVectorSpace.getZero(3)124 val w = listOf(zero, zero, zero).toNumVector()125 v shouldBe w126 }127 "(0, 0, 0) should be different from (0, 0)" {128 val v = numVectorSpace.getZero(3)129 val w = numVectorSpace.getZero(2)130 v shouldNotBe w131 }132 "vectorSpace.fromValueList(emptyList()) and vectorSpace.getZero(0) should return the same element" {133 val v = numVectorSpace.fromValueList(emptyList())134 val w = numVectorSpace.getZero(0)135 v shouldBe w136 }137 "(1,2) dot (-1, 3) should be 5" {138 val v = listOf(one, two).toNumVector()139 val w = listOf(-one, three).toNumVector()140 (v dot w) shouldBe five141 }142 "(0, 0, 0).isZero() should be true" {143 val v = listOf(zero, zero, zero).toNumVector()144 v.isZero().shouldBeTrue()145 }146 "(0, 1, 0).isZero() should be false" {147 val v = listOf(zero, one, zero).toNumVector()148 v.isZero().shouldBeFalse()149 }150 "Map.toNumVector() should return the same numVector as List.toNumVector()" {151 val v1 = mapOf(1 to one, 2 to two).toNumVector(4)152 val v2 = listOf(zero, one, two, zero).toNumVector()153 v1 shouldBe v2154 }155 "(0, 1, 2).toList() should be [0, 1, 2]" {156 val v = listOf(zero, one, two).toNumVector()157 v.toList() shouldBe listOf(zero, one, two)158 }159 "(0, 1, 2).toMap() should be {1: 1, 2: 2}" {160 val v = listOf(zero, one, two).toNumVector()161 v.toMap() shouldBe mapOf(1 to one, 2 to two)162 v.toMap()[0].shouldBeNull()163 }164 "test index access" {165 val v = listOf(zero, one, -two).toNumVector()166 v[0] shouldBe zero167 v[1] shouldBe one168 v[2] shouldBe (-two)169 }170 }171}172class IntRationalDenseNumVectorTest : FreeSpec({173 tags(numVectorTag, denseNumVectorTag, intRationalTag)174 include(denseNumVectorTest(DenseNumVectorSpaceOverIntRational))175 include(numVectorTest(DenseNumVectorSpaceOverIntRational))176 "test toString()" {177 DenseNumVectorSpaceOverIntRational.toString() shouldBe "DenseNumVectorSpace(IntRationalField)"178 }179})180class RationalDenseNumVectorTest : FreeSpec({181 tags(numVectorTag, denseNumVectorTag, rationalTag)182 include(denseNumVectorTest(DenseNumVectorSpaceOverRational))183 include(numVectorTest(DenseNumVectorSpaceOverRational))184 "test toString()" {185 DenseNumVectorSpaceOverRational.toString() shouldBe "DenseNumVectorSpace(RationalField)"186 }187})188class IntModpDenseNumVectorTest : FreeSpec({189 tags(numVectorTag, denseNumVectorTag, intModpTag)190 include(denseNumVectorTest(DenseNumVectorSpaceOverF7))191 include(numVectorTest(DenseNumVectorSpaceOverF7))192 "test toString()" {193 DenseNumVectorSpaceOverF7.toString() shouldBe "DenseNumVectorSpace(F_7)"194 }195})196class IntRationalSparseNumVectorTest : FreeSpec({197 tags(numVectorTag, sparseNumVectorTag, intRationalTag)198 include(sparseNumVectorTest(SparseNumVectorSpaceOverIntRational))199 include(numVectorTest(SparseNumVectorSpaceOverIntRational))200 "test toString()" {201 SparseNumVectorSpaceOverIntRational.toString() shouldBe "SparseNumVectorSpace(IntRationalField)"202 }203})204class RationalSparseNumVectorTest : FreeSpec({205 tags(numVectorTag, sparseNumVectorTag, rationalTag)206 include(sparseNumVectorTest(SparseNumVectorSpaceOverRational))207 include(numVectorTest(SparseNumVectorSpaceOverRational))208 "test toString()" {209 SparseNumVectorSpaceOverRational.toString() shouldBe "SparseNumVectorSpace(RationalField)"210 }211})212class IntModpSparseNumVectorTest : FreeSpec({213 tags(numVectorTag, sparseNumVectorTag, intModpTag)214 include(sparseNumVectorTest(SparseNumVectorSpaceOverF7))215 include(numVectorTest(SparseNumVectorSpaceOverF7))216 "test toString()" {217 SparseNumVectorSpaceOverF7.toString() shouldBe "SparseNumVectorSpace(F_7)"218 }219})...

Full Screen

Full Screen

FSetTests.kt

Source:FSetTests.kt Github

copy

Full Screen

1package edu.rice.fset2import io.kotest.core.spec.style.freeSpec3import io.kotest.matchers.shouldBe4import io.kotest.matchers.shouldNotBe5import io.kotest.matchers.types.shouldBeSameInstanceAs6import io.kotest.property.Arb7import io.kotest.property.arbitrary.arbitrary8import io.kotest.property.arbitrary.int9import io.kotest.property.arbitrary.list10import io.kotest.property.arbitrary.next11import io.kotest.property.checkAll12data class IntWithLameHash(val element: Int) {13 // Exercises that our set implementations still work as sets, even when the underlying14 // hash function gets tons of collisions.15 override fun hashCode() = element % 1016 override fun equals(other: Any?) = when (other) {17 is IntWithLameHash -> element == other.element18 else -> false19 }20}21val intWithLameHashGen = arbitrary { rs ->22 IntWithLameHash(Arb.int(0, 30).next(rs))23}24val listIntWithLameHashGen = arbitrary { rs ->25 Arb.list(intWithLameHashGen, 1..10).next(rs)26}27fun <E : Any> setsEqual(a: Set<E>, b: Set<E>): Boolean = a.containsAll(b) && b.containsAll(a)28internal fun fsetTests(29 algorithm: String,30 emptyStringSet: FSet<String>,31 emptyIntSet: FSet<IntWithLameHash>,32 emptyKVSet: FSet<KeyValuePair<String, Int>>33) = freeSpec {34 algorithm - {35 "basic inserts and membership (string)" {36 checkAll<List<String>> { inputs ->37 val testMe = emptyStringSet.addAll(inputs.asIterable())38 inputs.forEach { i ->39 val result = testMe.lookup(i)40 result shouldNotBe null41 val expected = inputs.filter { it == i }.toSet()42 setOf(result) shouldBe expected43 }44 }45 }46 "basic inserts and membership (restricted int)" {47 checkAll(listIntWithLameHashGen) { inputs ->48 val testMe = emptyIntSet.addAll(inputs.asIterable())49 val expectedSize = inputs.toSet().size50 val actualSize = testMe.size51 if (actualSize != expectedSize) {52 println(53 "expected: ${54 inputs.toSet()55 .sortedWith(compareBy<IntWithLameHash> { it.hashCode() }.thenBy { it.element })56 }"57 )58 println("actual:")59 testMe.debugPrint()60 }61 actualSize shouldBe expectedSize62 inputs.forEach { i ->63 val result = testMe.lookup(i)64 result shouldNotBe null65 val expected = inputs.filter { it == i }.toSet()66 setOf(result) shouldBe expected67 }68 }69 }70 "queries for missing values (restricted int)" {71 checkAll(listIntWithLameHashGen, intWithLameHashGen) { inputs, other ->72 val testMe = emptyIntSet.addAll(inputs.asIterable())73 val result = testMe.lookup(other)74 if (inputs.contains(other)) {75 result shouldBe other76 } else {77 result shouldBe null78 }79 }80 }81 "removing a value and set equality (restricted int)" {82 checkAll(listIntWithLameHashGen, intWithLameHashGen) { inputs, other ->83 val testMe = emptyIntSet.addAll(inputs.asIterable())84 val testMePlus = testMe + other85 val testMinus = testMePlus - other86 // We're testing that we have the expected set behavior, and we're87 // exercising our equals() methods versus the setsEqual() code88 // above that uses Kotlin logic from Container. (Our own equals()89 // methods can take advantage of internal structure and hopefully90 // run faster.)91 if (inputs.contains(other)) {92 val setsE = setsEqual(testMe, testMePlus)93 setsE shouldBe true94 testMe shouldBe testMePlus95 val testMeHash = testMe.hashCode()96 val testMePlusHash = testMePlus.hashCode()97 if (testMePlusHash != testMeHash) {98 // slightly more useful debugging output than just a failed assertion99 println("These should be the same!")100 testMe.debugPrint()101 println()102 testMePlus.debugPrint()103 }104 testMeHash shouldBe testMePlusHash105 setsEqual(testMe, testMinus) shouldBe false106 testMe shouldNotBe testMinus107 } else {108 val setsE = setsEqual(testMe, testMinus)109 setsE shouldBe true110 testMe shouldBe testMinus111 val testMeHash = testMe.hashCode()112 val testMinusHash = testMinus.hashCode()113 if (testMeHash != testMinusHash) {114 // slightly more useful debugging output than just a failed assertion115 println("These should be the same!")116 testMe.debugPrint()117 println()118 testMinus.debugPrint()119 }120 testMeHash shouldBe testMinusHash121 setsEqual(testMe, testMePlus) shouldBe false122 testMe shouldNotBe testMePlus123 }124 }125 }126 "removing everything, ending up with nothing (strings)" {127 checkAll<List<String>> { inputs ->128 val fullSet = emptyStringSet.addAll(inputs.asIterable())129 val emptySetAgain = fullSet.removeAll(inputs.shuffled().asIterable())130// println("Stats: ${fullSet.statistics()} -> ${emptySetAgain.statistics()}")131 emptySetAgain shouldBe emptyStringSet132 }133 }134 "key-value insertion, removal, update (strings)" {135 checkAll<List<String>, String> { base, query ->136 val fullSet = emptyKVSet.addAll(base.map { kv(it, it.length) })...

Full Screen

Full Screen

PreparedColorContainerTest.kt

Source:PreparedColorContainerTest.kt Github

copy

Full Screen

...18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN20 * THE SOFTWARE.21 */22package animatedledstrip.test.colors23import animatedledstrip.colors.ColorContainer24import animatedledstrip.colors.PreparedColorContainer25import animatedledstrip.colors.shift26import io.kotest.core.spec.style.StringSpec27import io.kotest.matchers.booleans.shouldBeFalse28import io.kotest.matchers.booleans.shouldBeTrue29import io.kotest.matchers.collections.shouldContainExactly30import io.kotest.matchers.shouldBe31import io.kotest.matchers.shouldNotBe32import io.kotest.matchers.types.shouldBeSameInstanceAs33import io.kotest.matchers.types.shouldNotBeSameInstanceAs34import io.kotest.property.Arb35import io.kotest.property.arbitrary.filter36import io.kotest.property.arbitrary.int37import io.kotest.property.arbitrary.list38import io.kotest.property.arbitrary.next39import io.kotest.property.checkAll40import kotlin.test.assertTrue41class PreparedColorContainerTest : StringSpec(42 {43 "get" {44 checkAll(Arb.int(0..0xFFFFFF),45 Arb.int(0..0xFFFFFF),46 Arb.int(0..0xFFFFFF),47 Arb.int(0..0xFFFFFF)) { c1, c2, c3, c4 ->48 val testCC = PreparedColorContainer(listOf(c1, c2, c3, c4), listOf(c1, c2, c3, c4))49 testCC[0] shouldBe c150 testCC[1] shouldBe c251 testCC[2] shouldBe c352 testCC[3] shouldBe c453 testCC[5] shouldBe 054 testCC.color shouldBe 055 }56 }57 "equality" {58 checkAll(25, Arb.list(Arb.int(0, 0xFFFFFF), 1..500)) { c ->59 checkAll(10, Arb.int(1..500)) { len ->60 val testPCC = ColorContainer(c.toMutableList()).prepare(len)61 checkAll(5, Arb.int(1..500).filter { it != len }) { len2 ->62 testPCC shouldBe ColorContainer(c.toMutableList()).prepare(len2)63 testPCC.hashCode() shouldNotBe ColorContainer(c.toMutableList()).prepare(len2).hashCode()64 }65 }66 }67 }68 "string" {69 ColorContainer(0xFF3B82).prepare(1).toString() shouldBe "[ff3b82]"70 ColorContainer(0xFF7B50, 0xFFFFFF).prepare(2).toString() shouldBe "[ff7b50, ffffff]"71 ColorContainer().prepare(1).toString() shouldBe "[0]"72 }73 "contains" {74 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..1500), Arb.int(1..1500)) { c, n ->75 val testPCC = ColorContainer(c.toMutableList()).prepare(n)76 for (i in c) {77 if (n >= c.size) (i in testPCC).shouldBeTrue()78 }79 for (i in Arb.list(Arb.int().filter { it !in c }, 10..10).next())80 (i in testPCC).shouldBeFalse()81 }82 }83 "prepare" {84 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..1500), Arb.int(1..1500)) { c, n ->85 val testPCC = ColorContainer(c.toMutableList()).prepare(n)86 testPCC.prepare(n).colors.shouldContainExactly(testPCC.colors)87 testPCC.prepare(n) shouldBeSameInstanceAs testPCC88 testPCC.prepare(n+1).colors shouldNotBe testPCC.colors89 testPCC.prepare(n+1) shouldNotBeSameInstanceAs testPCC90 }91 }92 "size" {93 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..1500), Arb.int(1..1500)) { c, n ->94 ColorContainer(c.toMutableList()).prepare(n).size shouldBe n95 }96 }97 "toColorContainer" {98 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..1500), Arb.int(1..1500)) { c, n ->99 val testPCC = ColorContainer(c.toMutableList()).prepare(n)100 val testCC = testPCC.toColorContainer()101 testCC.colors.shouldContainExactly(testPCC.colors)102 if (n != c.size) testCC shouldNotBe testPCC103 else testCC shouldBe testPCC104 }105 }106 "original ColorContainer" {107 checkAll(Arb.list(Arb.int(0..0xFFFFFF), 1..500), Arb.int(1..500)) { c, n ->108 val testPCC = ColorContainer(c.toMutableList()).prepare(n)109 val testCC = testPCC.originalColorContainer()110 testCC.colors.shouldContainExactly(c)111 testCC shouldBe testPCC112 }113 }114 "offset by".config(enabled = false) {115 val c = ColorContainer(116 0x0000FF, 0x00FFFF, 0xFF00FF,117 0x00FF00, 0xFF0000, 0xFFFFFF,118 ).prepare(6)119 assertTrue {120 c.colors ==121 listOf<Long>(122 0x0000FF, 0x00FFFF, 0xFF00FF,123 0x00FF00, 0xFF0000, 0xFFFFFF,124 )125 }...

Full Screen

Full Screen

UserHandlerTest.kt

Source:UserHandlerTest.kt Github

copy

Full Screen

1package org.tesserakt.diskordin.core.cache.handler2import io.kotest.assertions.asClue3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.nulls.shouldBeNull5import io.kotest.matchers.nulls.shouldNotBeNull6import io.kotest.matchers.shouldBe7import io.kotest.matchers.types.shouldBeTypeOf8import kotlinx.coroutines.runBlocking9import org.tesserakt.diskordin.core.cache.CacheSnapshotBuilder.Companion.mutate10import org.tesserakt.diskordin.core.cache.MemoryCacheSnapshot11import org.tesserakt.diskordin.core.client.InternalTestAPI12import org.tesserakt.diskordin.core.data.asSnowflake13import org.tesserakt.diskordin.core.data.json.response.IDUserResponse14import org.tesserakt.diskordin.core.data.json.response.MessageUserResponse15import org.tesserakt.diskordin.core.data.json.response.UserResponse16import org.tesserakt.diskordin.core.data.json.response.unwrap17import org.tesserakt.diskordin.core.entity.IUser18import org.tesserakt.diskordin.impl.core.client.DiscordClientBuilder19import org.tesserakt.diskordin.impl.core.entity.MessageUser20import org.tesserakt.diskordin.impl.core.entity.Self21import org.tesserakt.diskordin.rest.WithoutRest22@InternalTestAPI23class UserHandlerTest : FunSpec({24 runBlocking {25 DiscordClientBuilder[WithoutRest] {26 +disableTokenVerification()27 }28 }29 val id = 12345678910.asSnowflake()30 val fakeUser = UserResponse<IUser>(31 id,32 "Test",33 1234,34 "*hash*",35 bot = true,36 mfa_enabled = false,37 locale = "ru-RU",38 publicFlags = 0,39 premium_type = 040 ).unwrap()41 val fakeIdUser = IDUserResponse(42 id,43 "Test2",44 1235,45 null,46 bot = false,47 mfaEnabled = true,48 locale = "Aether",49 verified = false,50 email = "Overworld",51 publicFlags = 1,52 premiumType = 1,53 system = null54 ).unwrap()55 val fakeMessageUser = MessageUserResponse(56 "Test3",57 id,58 1236,59 "not a hash"60 ).unwrap()61 context("updater") {62 val handler = UserUpdater63 test("Item should appear after adding") {64 val cache = handler.handleAndGet(MemoryCacheSnapshot.empty().mutate(), fakeUser)65 cache.getUser(id).shouldNotBeNull()66 }67 test("Fields of user should update after adding idUser") {68 var cache = MemoryCacheSnapshot.empty().mutate()69 cache = handler.handleAndGet(cache, fakeUser)70 cache = handler.handleAndGet(cache, fakeIdUser)71 val cachedUser = cache.getUser(id)72 cachedUser.shouldBeTypeOf<Self>()73 cachedUser.raw.asClue {74 it.username shouldBe "Test2"75 it.discriminator shouldBe 123576 it.avatar shouldBe "*hash*"77 it.bot shouldBe false78 it.mfa_enabled shouldBe true79 it.locale shouldBe "Aether"80 it.publicFlags shouldBe 181 it.premium_type shouldBe 182 }83 }84 test("Fields of user should update after adding messageUser") {85 var cache = MemoryCacheSnapshot.empty().mutate()86 cache = handler.handleAndGet(cache, fakeUser)87 cache = handler.handleAndGet(cache, fakeMessageUser)88 val cachedUser = cache.getUser(id)89 cachedUser.shouldBeTypeOf<MessageUser>()90 cachedUser.raw shouldBe (fakeMessageUser as MessageUser).raw91 }92 test("Fields of idUser should update after adding user") {93 var cache = MemoryCacheSnapshot.empty().mutate()94 cache = handler.handleAndGet(cache, fakeIdUser)95 cache = handler.handleAndGet(cache, fakeUser)96 val cachedUser = cache.getUser(id)97 cachedUser.shouldBeTypeOf<Self>()98 cachedUser.raw shouldBe (fakeUser as Self).raw99 }100 test("Fields of idUser should update after adding messageUser") {101 var cache = MemoryCacheSnapshot.empty().mutate()102 cache = handler.handleAndGet(cache, fakeIdUser)103 cache = handler.handleAndGet(cache, fakeMessageUser)104 val cachedUser = cache.getUser(id)105 cachedUser.shouldBeTypeOf<MessageUser>()106 cachedUser.raw.asClue {107 it.username shouldBe "Test3"108 it.discriminator shouldBe 1236109 it.avatar shouldBe "not a hash"110 it.bot shouldBe false111 }112 }113 test("Fields of messageUser should update after adding user") {114 var cache = MemoryCacheSnapshot.empty().mutate()115 cache = handler.handleAndGet(cache, fakeMessageUser)116 cache = handler.handleAndGet(cache, fakeUser)117 val cachedUser = cache.getUser(id)118 cachedUser.shouldBeTypeOf<Self>()119 cachedUser.raw shouldBe (fakeUser as Self).raw120 }121 test("Fields of messageUser should update after adding idUser") {122 var cache = MemoryCacheSnapshot.empty().mutate()123 cache = handler.handleAndGet(cache, fakeMessageUser)124 cache = handler.handleAndGet(cache, fakeIdUser)125 val cachedUser = cache.getUser(id)126 cachedUser.shouldBeTypeOf<MessageUser>()127 cachedUser.raw.asClue {128 it.username shouldBe "Test2"129 it.discriminator shouldBe 1235130 it.avatar shouldBe "not a hash"131 it.bot shouldBe false132 }133 }134 }135 context("deleter") {136 val handler = UserDeleter137 test("Item should be deleted from cache") {138 val cache = MemoryCacheSnapshot.empty().copy(users = mapOf(id to fakeIdUser)).mutate()139 handler.handle(cache, fakeIdUser)140 cache.getUser(id).shouldBeNull()141 }142 }143})...

Full Screen

Full Screen

GVectorTest.kt

Source:GVectorTest.kt Github

copy

Full Screen

...6import com.github.shwaka.kohomology.rationalTag7import com.github.shwaka.kohomology.specific.DenseNumVectorSpaceOverRational8import com.github.shwaka.kohomology.util.Sign9import com.github.shwaka.kohomology.vectsp.StringBasisName10import io.kotest.assertions.throwables.shouldThrow11import io.kotest.core.NamedTag12import io.kotest.core.spec.style.FreeSpec13import io.kotest.core.spec.style.freeSpec14import io.kotest.matchers.booleans.shouldBeFalse15import io.kotest.matchers.booleans.shouldBeTrue16import io.kotest.matchers.shouldBe17import io.kotest.matchers.shouldNotBe18import io.kotest.matchers.types.shouldBeSameInstanceAs19import io.kotest.matchers.types.shouldNotBeSameInstanceAs20val gVectorTag = NamedTag("GVector")21fun <S : Scalar, V : NumVector<S>> gVectorTest(numVectorSpace: NumVectorSpace<S, V>) = freeSpec {22 "graded vector test" - {23 val gVectorSpace = GVectorSpace.fromStringBasisNamesWithIntDegree(numVectorSpace, "V") { degree ->24 (0 until degree).map { "v$it" }25 }26 gVectorSpace.context.run {27 "fromCoeffMap() should give the same gVector as fromCoeffList()" {28 val v1 = gVectorSpace.fromCoeffList(listOf(zero, one, two), 3)29 val v2 = gVectorSpace.fromCoeffMap(mapOf(1 to one, 2 to two), 3)30 v2 shouldBe v131 }32 "GVectors with the same coefficients should have the same hashCode" {33 val v1 = gVectorSpace.fromCoeffList(listOf(one, two), 2)34 val v2 = gVectorSpace.fromCoeffList(listOf(one, two), 2)35 v1 shouldNotBeSameInstanceAs v236 v1.hashCode() shouldBe v2.hashCode()37 }38 "addition test" {39 val v = gVectorSpace.fromCoeffList(listOf(one, zero), 2)40 val expected = gVectorSpace.fromCoeffList(listOf(two, zero), 2)41 (v + v) shouldBe expected42 (v + v) shouldNotBe v43 }44 "multiplication with Sign" {45 val v = gVectorSpace.fromCoeffList(listOf(one, -two, zero), 3)46 (v * Sign.PLUS) shouldBe v47 (Sign.PLUS * v) shouldBe v48 (v * Sign.MINUS) shouldBe -v49 (Sign.MINUS * v) shouldBe -v50 }51 "(0, 0).isZero() should be true" {52 val v = gVectorSpace.fromCoeffList(listOf(zero, zero), 2)...

Full Screen

Full Screen

LocationSpec.kt

Source:LocationSpec.kt Github

copy

Full Screen

1package locutus.tools.math2import io.kotest.core.spec.Order3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.doubles.*5import io.kotest.matchers.ints.shouldBeInRange6import io.kotest.matchers.shouldBe7import kweb.util.random8import locutus.tools.crypto.hash9import mu.KotlinLogging10import java.util.*11import java.util.concurrent.atomic.AtomicInteger12import kotlin.math.roundToInt13private val tolerance = 0.00000000114private val logger = KotlinLogging.logger {}15@Order(0)16@ExperimentalUnsignedTypes17class LocationSpec : FunSpec({18 test("Distance") {19 (Location(0.4) distance Location(0.6)) shouldBe (0.2 plusOrMinus tolerance)20 (Location(0.1) distance Location(0.9)) shouldBe (0.2 plusOrMinus tolerance)21 }22 test("fromByteArray simple") {23 Location.fromByteArray(ubyteArrayOf(UByte.MIN_VALUE)).value shouldBe (0.0 plusOrMinus tolerance)24 Location.fromByteArray(ubyteArrayOf(UByte.MAX_VALUE)).value shouldBe (1.0 plusOrMinus 0.01)25 Location.fromByteArray(ubyteArrayOf(UByte.MAX_VALUE, UByte.MAX_VALUE)).value shouldBe (1.0 plusOrMinus 0.0001)26 Location.fromByteArray(ubyteArrayOf(UByte.MAX_VALUE, UByte.MAX_VALUE, UByte.MAX_VALUE)).value shouldBe (1.0 plusOrMinus 0.000001)27 Location.fromByteArray(ubyteArrayOf(UByte.MIN_VALUE, UByte.MAX_VALUE)).value shouldBe ((1.0/256.0) plusOrMinus 0.001)28 }29 test("fromByteArray precision") {30 val randomBytes = ByteArray(20)31 random.nextBytes(randomBytes)32 val randomUBytes = randomBytes.asUByteArray()33 for (precision in 1 .. 7) {34 val pos = Location.fromByteArray(randomUBytes, precision)35 logger.info("precision: $precision position: $pos")36 }37 }38 test("Ensure locations generated from random hashes are evenly distributed") {39 val buckets = TreeMap<Double, AtomicInteger>()40 for (i in 0 .. 10000) {41 val nextDouble = random.nextDouble()42 val toString = nextDouble.toString()43 val toByteArray = toString.toByteArray()44 val randomBA = toByteArray.hash()45 val location = Location.fromByteArray(randomBA.asUByteArray())46 val bucket = (location.value * 10.0).roundToInt().toDouble()/10.047 buckets.computeIfAbsent(bucket) { AtomicInteger(0) }.incrementAndGet()48 }49 buckets[0.0]!!.get() shouldBeInRange(400 .. 600)50 buckets[1.0]!!.get() shouldBeInRange(400 .. 600)51 for (n in 2 .. 9) {52 buckets[n.toDouble() / 10.0]!!.get() shouldBeInRange(900 .. 1100)...

Full Screen

Full Screen

TestVec2.kt

Source:TestVec2.kt Github

copy

Full Screen

1import io.kotest.matchers.doubles.shouldBeExactly2import io.kotest.matchers.ints.shouldBeExactly3import io.kotest.matchers.types.shouldHaveSameHashCodeAs4import io.lacuna.artifex.Vec25import kotlin.test.Test6import org.openrndr.kartifex.Vec2 as KVec27class TestVec2 {8 @Test9 fun testHash() {10 run {11 val v2 = Vec2(0.0, 0.0)12 val kv2 = KVec2(0.0, 0.0)13 v2.shouldHaveSameHashCodeAs(kv2)14 }15 run {16 val v2 = Vec2(2.0, 2.1231)17 val kv2 = KVec2(2.0, 2.1231)18 v2.shouldHaveSameHashCodeAs(kv2)19 }20 }21 @Test22 fun testCompare() {23 val v2 = Vec2(0.0, 0.0)24 val kv2 = KVec2(0.0, 0.0)25 v2.compareTo(v2).shouldBeExactly(kv2.compareTo(kv2))26 val v2a = Vec2(1.0, 0.0)27 val kv2a = KVec2(1.0, 0.0)28 v2a.compareTo(v2).shouldBeExactly(kv2a.compareTo(kv2))29 v2.compareTo(v2a).shouldBeExactly(kv2.compareTo(kv2a))30 }31 @Test32 fun testPseudoNorm() {33 val v2 = Vec2(2100.0, 3220.0)34 val pn = v2.pseudoNorm()35 val kv2 = KVec2(2100.0, 3220.0)36 val kpn = kv2.pseudoNorm()37 pn.x.shouldBeExactly(kpn.x)38 pn.y.shouldBeExactly(kpn.y)39 }40}

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.types.hash2 import io.kotest.matchers.types.shouldBeInstanceOf3 import io.kotest.matchers.types.shouldBeSameInstanceAs4 import io.kotest.matchers.types.shouldBeSameInstanceAs5 import io.kotest.matchers.types.shouldBeSameInstanceAs6 import io.kotest.matchers.types.shouldBeSameInstanceAs7 import io.kotest.matchers.types.shouldBeSameInstanceAs8 import io.kotest.matchers.types.shouldBeSameInstanceAs9 import io.kotest.matchers.types.shouldBeSameInstanceAs10 import io.kotest.matchers.types.shouldBeSameInstanceAs11 import io.kotest.matchers.types.shouldBeSameInstanceAs12 import io.kotest.matchers.types.shouldBeSameInstanceAs13 import io.kotest.matchers.types.shouldBeSameInstanceAs14 import io.kotest.matchers.types.shouldBeSameInstanceAs

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1fun testHash() {2hash(1) shouldBe hash(1)3hash(1) shouldBeNot hash(2)4hash(1) shouldNotBe hash(2)5}6}7fun testHash() {8hash(1) shouldBe hash(1)9hash(1) shouldBeNot hash(2)10hash(1) shouldNotBe hash(2)11}12}13fun testHash() {14hash(1) shouldBe hash(1)15hash(1) shouldBeNot hash(2)16hash(1) shouldNotBe hash(2)17}18}19fun testHash() {20hash(1) shouldBe hash(1)21hash(1) shouldBeNot hash(2)22hash(1) shouldNotBe hash(2)23}24}25fun testHash() {26hash(1) shouldBe hash(1)27hash(1) shouldBeNot hash(2)28hash(1) shouldNotBe hash(2)29}30}31fun testHash() {32hash(1) shouldBe hash(1)33hash(1) shouldBeNot hash(2)34hash(1) shouldNotBe hash(2)35}36}37fun testHash() {38hash(1) shouldBe hash(1)39hash(1) shouldBeNot hash(2)40hash(1) shouldNotBe hash(2)41}42}43fun testHash() {44hash(1) shouldBe hash(1)45hash(1) shouldBeNot hash(2)46hash(1) shouldNotBe hash(2)47}48}49fun testHash() {50hash(1) shouldBe hash(1)51hash(1) shouldBeNot hash(2)52hash(1) shouldNot

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1 val result = hash("Hello World")2 result.shouldBe(Hash("Hello World"))3 }4 fun `test should fail`() {5 val result = hash("Hello World")6 result.shouldBe(Hash("Hello World 2"))7 }8 fun `test should fail with wrong type`() {9 val result = hash("Hello World")10 result.shouldBe(Hash(123))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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful