How to use exactly method of io.kotest.matchers.floats.matchers class

Best Kotest code snippet using io.kotest.matchers.floats.matchers.exactly

PlayerTest.kt

Source:PlayerTest.kt Github

copy

Full Screen

1package land.vani.mockpaper.player2import com.destroystokyo.paper.event.player.PlayerPostRespawnEvent3import io.kotest.assertions.fail4import io.kotest.core.spec.style.ShouldSpec5import io.kotest.matchers.collections.shouldContainExactly6import io.kotest.matchers.doubles.shouldNotBeExactly7import io.kotest.matchers.floats.shouldBeExactly8import io.kotest.matchers.ints.shouldBeExactly9import io.kotest.matchers.longs.shouldBeExactly10import io.kotest.matchers.longs.shouldBeGreaterThan11import io.kotest.matchers.longs.shouldNotBeExactly12import io.kotest.matchers.nulls.shouldBeNull13import io.kotest.matchers.nulls.shouldNotBeNull14import io.kotest.matchers.shouldBe15import io.kotest.matchers.types.shouldBeInstanceOf16import io.kotest.property.Exhaustive17import io.kotest.property.checkAll18import io.kotest.property.exhaustive.enum19import io.kotest.property.exhaustive.exhaustive20import io.kotest.property.exhaustive.filterNot21import io.papermc.paper.event.player.AsyncChatEvent22import land.vani.mockpaper.MockPaper23import land.vani.mockpaper.MockPlugin24import land.vani.mockpaper.ServerMock25import land.vani.mockpaper.inventory.EnderChestInventoryMock26import land.vani.mockpaper.inventory.InventoryMock27import land.vani.mockpaper.inventory.InventoryViewMock28import land.vani.mockpaper.randomLocation29import net.kyori.adventure.text.Component30import org.bukkit.BanList31import org.bukkit.GameMode32import org.bukkit.Material33import org.bukkit.command.CommandSender34import org.bukkit.entity.EntityType35import org.bukkit.event.EventHandler36import org.bukkit.event.Listener37import org.bukkit.event.block.BlockBreakEvent38import org.bukkit.event.block.BlockDamageEvent39import org.bukkit.event.block.BlockPlaceEvent40import org.bukkit.event.inventory.InventoryCloseEvent41import org.bukkit.event.inventory.InventoryType42import org.bukkit.event.player.PlayerExpChangeEvent43import org.bukkit.event.player.PlayerLevelChangeEvent44import org.bukkit.event.player.PlayerMoveEvent45import org.bukkit.event.player.PlayerRespawnEvent46import org.bukkit.event.player.PlayerToggleFlightEvent47import org.bukkit.event.player.PlayerToggleSneakEvent48import org.bukkit.event.player.PlayerToggleSprintEvent49import java.util.UUID50@Suppress("DEPRECATION")51class PlayerTest : ShouldSpec({52 lateinit var server: ServerMock53 lateinit var uuid: UUID54 lateinit var player: PlayerMock55 beforeEach {56 server = MockPaper.mock(57 object : ServerMock() {58 private var tick = 059 override val currentServerTime: Long60 get() = super.currentServerTime + tick++61 }62 )63 uuid = UUID.randomUUID()64 player = PlayerMock(server, randomPlayerName(), uuid)65 }66 afterEach {67 MockPaper.unmock()68 }69 should("entityType is Player") {70 player.type shouldBe EntityType.PLAYER71 }72 context("displayName") {73 should("constructor") {74 val name = randomPlayerName()75 player = PlayerMock(server, name, uuid)76 player.displayName() shouldBe Component.text(name)77 }78 should("displayName(Component)") {79 player.displayName(Component.text("some display name"))80 player.displayName() shouldBe Component.text("some display name")81 }82 should("displayName(null)") {83 val name = randomPlayerName()84 player = PlayerMock(server, name, uuid)85 player.displayName(Component.text("some display name"))86 player.displayName(null)87 player.displayName() shouldBe Component.text(name)88 }89 should("getDisplayName") {90 val name = randomPlayerName()91 player = PlayerMock(server, name, uuid)92 player.displayName shouldBe name93 }94 should("setDisplayName") {95 @Suppress("DEPRECATION")96 player.setDisplayName("some display name")97 player.displayName shouldBe "some display name"98 player.displayName() shouldBe Component.text("some display name")99 }100 }101 context("playerList") {102 context("name") {103 should("playerListName is default player.displayName()") {104 player.playerListName() shouldBe player.displayName()105 }106 should("set playerListName") {107 player.playerListName(Component.text("some player list name"))108 player.playerListName() shouldBe Component.text("some player list name")109 }110 }111 context("header") {112 should("playerListHeader is default null") {113 player.playerListHeader().shouldBeNull()114 }115 should("playerListHeader(Component))") {116 player.sendPlayerListHeader(Component.text("some player list header"))117 player.playerListHeader().shouldNotBeNull()118 player.playerListHeader() shouldBe Component.text("some player list header")119 }120 should("setPlayerListHeader(String)") {121 player.playerListHeader = "some player list header"122 player.playerListHeader.shouldNotBeNull()123 player.playerListHeader shouldBe "some player list header"124 player.playerListHeader() shouldBe Component.text("some player list header")125 }126 }127 context("footer") {128 should("playerListFooter is default null") {129 player.playerListFooter().shouldBeNull()130 }131 should("playerListFooter(Component)") {132 player.sendPlayerListFooter(Component.text("some player list footer"))133 player.playerListFooter().shouldNotBeNull()134 player.playerListFooter() shouldBe Component.text("some player list footer")135 }136 should("setPlayerListFooter(String)") {137 player.playerListFooter = "some player list footer"138 player.playerListFooter.shouldNotBeNull()139 player.playerListFooter shouldBe "some player list footer"140 player.playerListFooter() shouldBe Component.text("some player list footer")141 }142 }143 should("sendPlayerListHeaderAndFooter") {144 player.sendPlayerListHeaderAndFooter(145 Component.text("some player list header"),146 Component.text("some player list footer"),147 )148 player.playerListHeader() shouldBe Component.text("some player list header")149 player.playerListFooter() shouldBe Component.text("some player list footer")150 }151 }152 context("compassTarget") {153 should("compassTarget is default player location") {154 player.compassTarget shouldBe player.location155 }156 should("set compassTarget") {157 val location = randomLocation(player.world)158 player.compassTarget = location159 player.compassTarget shouldBe location160 }161 }162 should("respawn") {163 val location = randomLocation(player.world)164 player.setBedSpawnLocation(location, true)165 player.health = 0.0166 player.respawn()167 player.location shouldBe location168 player.health shouldNotBeExactly 0.0169 server.pluginManager.assertEventFired<PlayerRespawnEvent>()170 server.pluginManager.assertEventFired<PlayerPostRespawnEvent>()171 player.location shouldBe location172 }173 should("simulatePlayerMove") {174 val location = randomLocation(player.world)175 val event = player.simulatePlayerMove(location)176 event.isCancelled shouldBe false177 server.pluginManager.assertEventFired<PlayerMoveEvent> { it == event }178 event.to shouldBe location179 }180 context("gameMode") {181 should("gameMode is default survival") {182 player.gameMode shouldBe GameMode.SURVIVAL183 }184 should("set gameMode") {185 player.gameMode = GameMode.CREATIVE186 player.gameMode shouldBe GameMode.CREATIVE187 }188 }189 should("isOnline is default true") {190 player.isOnline shouldBe true191 }192 context("isBanned") {193 should("isBanned is default false") {194 player.isBanned shouldBe false195 }196 should("banned player") {197 server.getBanList(BanList.Type.NAME).addBan(player.name, null, null, null)198 player.isBanned shouldBe true199 }200 }201 context("isWhitelisted") {202 should("isWhitelisted is default false") {203 player.isWhitelisted shouldBe false204 }205 should("whitelist") {206 player.isWhitelisted = true207 player.isWhitelisted shouldBe true208 }209 }210 context("getPlayer") {211 should("getPlayer is default not null") {212 player.player.shouldNotBeNull()213 }214 }215 should("firstPlayed") {216 player = PlayerMock(server, randomPlayerName(), UUID.randomUUID())217 player.hasPlayedBefore() shouldBe false218 player.firstPlayed shouldBeExactly 0219 player.lastPlayed shouldBeExactly 0220 server.addPlayer(player)221 val firstPlayed = player.firstPlayed222 player.hasPlayedBefore() shouldBe true223 firstPlayed shouldBeGreaterThan 0224 firstPlayed shouldBeExactly player.lastPlayed225 // Player reconnects226 server.addPlayer(player)227 player.hasPlayedBefore() shouldBe true228 firstPlayed shouldBeExactly player.firstPlayed229 player.firstPlayed shouldNotBeExactly player.lastPlayed230 }231 context("inventory") {232 should("twice inventory are same") {233 player.inventory shouldBe player.inventory234 }235 should("enderChest") {236 player.enderChest.shouldBeInstanceOf<EnderChestInventoryMock>()237 }238 should("openInventory is default CRAFTING") {239 val view = player.openInventory240 view.shouldNotBeNull()241 view.type shouldBe InventoryType.CRAFTING242 }243 should("openInventory") {244 val inventory = InventoryViewMock(245 player,246 InventoryMock.Crafting,247 InventoryMock(),248 InventoryType.CHEST249 )250 player.openInventory(inventory)251 player.openInventory shouldBe inventory252 }253 should("closeInventory") {254 val inventory = InventoryViewMock(255 player,256 InventoryMock.Crafting,257 InventoryMock(),258 InventoryType.CHEST259 )260 player.openInventory(inventory)261 player.closeInventory()262 player.openInventory.type shouldBe InventoryType.CRAFTING263 server.pluginManager.assertEventFired<InventoryCloseEvent>()264 }265 }266 should("chat") {267 player.chat("some message")268 player.assertSaid("some message")269 player.assertNoMoreSaid()270 @Suppress("DEPRECATION")271 server.pluginManager.assertEventFired<org.bukkit.event.player.PlayerChatEvent>()272 @Suppress("DEPRECATION")273 server.pluginManager.assertEventFired<org.bukkit.event.player.AsyncPlayerChatEvent>()274 server.pluginManager.assertEventFired<AsyncChatEvent>()275 }276 should("perform command") {277 val plugin = server.pluginManager.loadPlugin<MockPlugin>(278 """279 name: MockPlugin280 version: "1.0.0"281 main: ${MockPlugin::class.java.name}282 commands:283 test: {}284 """.trimIndent()285 )286 var executed = false287 var executedSender: CommandSender? = null288 var executedArgs: Array<String>? = null289 plugin.getCommand("test")!!.setExecutor { sender, _, _, args ->290 executed = true291 executedSender = sender292 executedArgs = args293 true294 }295 player.performCommand("test foo bar") shouldBe true296 executed shouldBe true297 executedSender shouldBe player298 executedArgs shouldContainExactly arrayOf("foo", "bar")299 }300 context("sneak") {301 should("player is default not sneaking") {302 player.isSneaking shouldBe false303 }304 should("set sneaking") {305 player.isSneaking = true306 player.isSneaking shouldBe true307 }308 should("eyeHeight") {309 player.isSneaking = true310 player.eyeHeight shouldNotBeExactly player.getEyeHeight(true)311 }312 should("simulateSneak") {313 val event = player.simulateSneaking(true)314 player.isSneaking shouldBe true315 server.pluginManager.assertEventFired<PlayerToggleSneakEvent> {316 it == event317 }318 event.player shouldBe player319 event.isSneaking shouldBe true320 }321 }322 context("sprint") {323 should("player is default not sprinting") {324 player.isSprinting shouldBe false325 }326 should("set sprinting") {327 player.isSprinting = true328 player.isSprinting shouldBe true329 }330 should("simulateSprint") {331 val event = player.simulateSprinting(true)332 player.isSprinting shouldBe true333 server.pluginManager.assertEventFired<PlayerToggleSprintEvent> {334 it == event335 }336 event.player shouldBe player337 event.isSprinting shouldBe true338 }339 }340 context("bedSpawnLocation") {341 should("set bedSpawnLocation") {342 val location = randomLocation(player.world)343 location.block.type = Material.LIGHT_BLUE_BED344 player.bedSpawnLocation.shouldBeNull()345 player.bedSpawnLocation = location346 player.bedSpawnLocation shouldBe location347 player.bedSpawnLocation = null348 player.bedSpawnLocation.shouldBeNull()349 }350 should("set bedSpawnLocation force") {351 val location = randomLocation(player.world)352 player.bedSpawnLocation = location353 player.bedSpawnLocation.shouldBeNull()354 player.setBedSpawnLocation(location, true)355 player.bedSpawnLocation shouldBe location356 }357 }358 context("breakBlock") {359 should("success") {360 val location = randomLocation(player.world)361 location.block.type = Material.DIRT362 player.breakBlock(location.block) shouldBe true363 location.block.type shouldBe Material.AIR364 }365 should("failed") {366 val location = randomLocation(player.world)367 player.gameMode = GameMode.ADVENTURE368 player.breakBlock(location.block) shouldBe false369 }370 }371 context("simulateBlockDamage") {372 should("survival") {373 player.gameMode = GameMode.SURVIVAL374 val location = randomLocation(player.world)375 val event = player.simulateBlocKDamage(location.block)376 event.shouldNotBeNull()377 event.isCancelled shouldBe false378 event.player shouldBe player379 server.pluginManager.assertEventFired<BlockDamageEvent>()380 server.pluginManager.clearEvents()381 }382 should("without survival") {383 checkAll(384 Exhaustive.enum<GameMode>().filterNot { it == GameMode.SURVIVAL }385 ) { gameMode ->386 player.gameMode = gameMode387 val location = randomLocation(player.world)388 player.simulateBlocKDamage(location.block).shouldBeNull()389 }390 }391 should("not insta break") {392 val plugin = server.pluginManager.createMockPlugin()393 player.gameMode = GameMode.SURVIVAL394 var isBroken = false395 server.pluginManager.registerEvents(396 object : Listener {397 @EventHandler398 fun onBlockDamage(event: BlockDamageEvent) {399 event.instaBreak = false400 }401 @EventHandler402 fun onBlockBreak(@Suppress("UNUSED_PARAMETER") event: BlockBreakEvent) {403 isBroken = true404 }405 },406 plugin407 )408 val location = randomLocation(player.world)409 location.block.type = Material.STONE410 val event = player.simulateBlocKDamage(location.block)411 event.shouldNotBeNull()412 event.isCancelled shouldBe false413 isBroken shouldBe false414 location.block.type shouldBe Material.STONE415 }416 should("insta break") {417 val plugin = server.pluginManager.createMockPlugin()418 player.gameMode = GameMode.SURVIVAL419 var brokenCount = 0420 server.pluginManager.registerEvents(421 object : Listener {422 @EventHandler423 fun onBlockDamage(event: BlockDamageEvent) {424 event.instaBreak = true425 }426 @EventHandler427 fun onBlockBreak(@Suppress("UNUSED_PARAMETER") event: BlockBreakEvent) {428 brokenCount++429 }430 },431 plugin432 )433 val location = randomLocation(player.world)434 location.block.type = Material.STONE435 val event = player.simulateBlocKDamage(location.block)436 event.shouldNotBeNull()437 event.isCancelled shouldBe false438 brokenCount shouldBeExactly 1439 location.block.type shouldBe Material.AIR440 }441 }442 context("simulateBlockBreak") {443 should("insta break") {444 val plugin = server.pluginManager.createMockPlugin()445 player.gameMode = GameMode.SURVIVAL446 var brokenCount = 0447 server.pluginManager.registerEvents(448 object : Listener {449 @EventHandler450 fun onBlockDamage(event: BlockDamageEvent) {451 event.instaBreak = true452 }453 @EventHandler454 fun onBlockBreak(@Suppress("UNUSED_PARAMETER") event: BlockBreakEvent) {455 brokenCount++456 }457 },458 plugin459 )460 val location = randomLocation(player.world)461 location.block.type = Material.STONE462 val event = player.simulateBlockBreak(location.block)463 event.shouldNotBeNull()464 event.isCancelled shouldBe false465 brokenCount shouldBeExactly 1466 location.block.type shouldBe Material.AIR467 }468 }469 // TODO: block state is not supported yet.470 xcontext("simulateBlockPlace") {471 should("valid") {472 val location = randomLocation(player.world)473 player.gameMode = GameMode.SURVIVAL474 val event = player.simulateBlockPlace(Material.STONE, location)475 event.shouldNotBeNull()476 event.isCancelled shouldBe false477 server.pluginManager.assertEventFired<BlockPlaceEvent>()478 location.block.type shouldBe Material.STONE479 }480 should("invalid") {481 val location = randomLocation(player.world)482 player.gameMode = GameMode.ADVENTURE483 val event = player.simulateBlockPlace(Material.STONE, location)484 server.pluginManager.assertEventNotFired<BlockPlaceEvent>()485 event.shouldBeNull()486 }487 }488 context("giveExp") {489 val expRequired = intArrayOf(490 7,491 9,492 11,493 13,494 15,495 17,496 19,497 21,498 23,499 25,500 27,501 29,502 31,503 33,504 35,505 37,506 42,507 47,508 52,509 57,510 62,511 67,512 72,513 77,514 82,515 87,516 92,517 97,518 102,519 107,520 112,521 121,522 130,523 139,524 148,525 157,526 166,527 175,528 184,529 193530 )531 should("negative") {532 player.exp = 0.5F533 player.level = 1534 player.giveExpLevels(-100)535 player.exp shouldBeExactly 0.0F536 player.level shouldBeExactly 0537 }538 should("some exp increase level") {539 checkAll(expRequired.withIndex().toList().exhaustive()) { (index, level) ->540 player.exp shouldBeExactly 0.0F541 player.giveExp(level)542 player.level shouldBeExactly index + 1543 }544 }545 should("some exp increase multiple levels") {546 player.giveExp(expRequired[0] + expRequired[1] + expRequired[2])547 player.level shouldBeExactly 3548 player.totalExperience shouldBeExactly expRequired[0] + expRequired[1] + expRequired[2]549 }550 should("some exp decrease level") {551 player.giveExp(expRequired[0] + expRequired[1])552 player.giveExp(-expRequired[1])553 player.level shouldBeExactly 1554 player.totalExperience shouldBeExactly expRequired[0]555 }556 should("some exp decrease multiple levels") {557 player.giveExp(expRequired[0] + expRequired[1])558 player.giveExp(-(expRequired[0] + expRequired[1]))559 player.level shouldBeExactly 0560 player.totalExperience shouldBeExactly 0561 }562 should("level event is fired") {563 val plugin = server.pluginManager.createMockPlugin()564 var levelCount = 0565 server.pluginManager.registerEvents(566 object : Listener {567 @EventHandler568 fun onLevelChanged(@Suppress("UNUSED_PARAMETER") event: PlayerLevelChangeEvent) {569 levelCount++570 }571 @EventHandler572 fun onExpChanged(@Suppress("UNUSED_PARAMETER") event: PlayerExpChangeEvent) {573 fail("PlayerExpChangeEvent should not be called")574 }575 },576 plugin577 )578 player.giveExp(expRequired[0])579 levelCount shouldBeExactly 1580 }581 should("no exp event is fired") {582 val plugin = server.pluginManager.createMockPlugin()583 server.pluginManager.registerEvents(584 object : Listener {585 @EventHandler586 fun onLevelChangeEvent(@Suppress("UNUSED_PARAMETER") event: PlayerLevelChangeEvent) {587 fail("PlayerLevelChangeEvent should not be called")588 }589 @EventHandler590 fun onExpChangeEvent(@Suppress("UNUSED_PARAMETER") event: PlayerExpChangeEvent) {591 fail("PlayerExpChangeEvent should not be called")592 }593 },594 plugin595 )596 player.giveExp(0)597 }598 }599 context("allowFlight") {600 should("allowFlight is default false") {601 player.allowFlight shouldBe false602 }603 should("set allowFlight") {604 player.allowFlight = true605 player.allowFlight shouldBe true606 }607 }608 context("hidePlayer") {609 should("other player default can see") {610 val player2 = server.addPlayer()611 player.canSee(player2) shouldBe true612 }613 @Suppress("DEPRECATION")614 should("deprecated hidePlayer") {615 val player2 = server.addPlayer()616 player.hidePlayer(player2)617 player.canSee(player2) shouldBe false618 player.showPlayer(player2)619 player.canSee(player2) shouldBe true620 }621 should("new hidePlayer") {622 val plugin = server.pluginManager.createMockPlugin()623 val player2 = server.addPlayer()624 player.hidePlayer(plugin, player2)625 player.canSee(player2) shouldBe false626 player.showPlayer(plugin, player2)627 player.canSee(player2) shouldBe true628 }629 @Suppress("DEPRECATION")630 should("old and new") {631 val plugin = server.pluginManager.createMockPlugin()632 val player2 = server.addPlayer()633 player.hidePlayer(plugin, player2)634 player.canSee(player2) shouldBe false635 player.showPlayer(player2)636 player.canSee(player2) shouldBe false637 player.showPlayer(plugin, player2)638 player.canSee(player2) shouldBe true639 }640 @Suppress("DEPRECATION")641 should("eachOther") {642 val plugin1 = server.pluginManager.createMockPlugin("plugin1")643 val plugin2 = server.pluginManager.createMockPlugin("plugin2")644 val player2 = server.addPlayer()645 player.hidePlayer(plugin1, player2)646 player.canSee(player2) shouldBe false647 player.hidePlayer(plugin2, player2)648 player.canSee(player2) shouldBe false649 player.hidePlayer(player2)650 player.canSee(player2) shouldBe false651 player.showPlayer(player2)652 player.canSee(player2) shouldBe false653 player.showPlayer(plugin2, player2)654 player.canSee(player2) shouldBe false655 player.showPlayer(plugin1, player2)656 player.canSee(player2) shouldBe true657 }658 }659 context("flying") {660 should("flying is default false") {661 player.isFlying shouldBe false662 }663 should("set flying") {664 player.isFlying = true665 player.isFlying shouldBe true666 }667 }668 should("simulateToggleFlight") {669 val event = player.simulateToggleFlight(true)670 event.shouldNotBeNull()671 event.isFlying shouldBe true672 player.isFlying shouldBe true673 server.pluginManager.assertEventFired<PlayerToggleFlightEvent>()674 }675 @Suppress("DEPRECATION")676 should("sendTitle") {677 player.sendTitle("some title", "some subtitle")678 player.nextTitle() shouldBe "some title"679 player.nextSubTitle() shouldBe "some subtitle"680 }681 context("saturation") {682 should("saturation is default 5.0") {683 player.saturation shouldBeExactly 5.0F684 }685 should("set saturation") {686 player.foodLevel = 20687 player.saturation = 8.0F688 player.saturation shouldBeExactly 8.0F689 player.foodLevel = 20690 player.saturation = 1000000.0F691 player.saturation shouldBeExactly 20.0F692 }693 }694})...

Full Screen

Full Screen

CoreTest.kt

Source:CoreTest.kt Github

copy

Full Screen

1package com.github.whyrising.y2import com.github.whyrising.y.collections.ArrayChunk3import com.github.whyrising.y.collections.PersistentQueue4import com.github.whyrising.y.collections.concretions.list.ChunkedSeq5import com.github.whyrising.y.collections.concretions.list.PersistentList.Empty6import com.github.whyrising.y.collections.concretions.map.MapEntry7import com.github.whyrising.y.collections.concretions.map.PersistentArrayMap8import com.github.whyrising.y.collections.concretions.map.PersistentHashMap9import com.github.whyrising.y.collections.concretions.vector.PersistentVector10import com.github.whyrising.y.collections.map.IPersistentMap11import com.github.whyrising.y.collections.seq.Seqable12import io.kotest.assertions.throwables.shouldThrowExactly13import io.kotest.core.spec.style.FreeSpec14import io.kotest.matchers.booleans.shouldBeFalse15import io.kotest.matchers.booleans.shouldBeTrue16import io.kotest.matchers.doubles.shouldBeExactly17import io.kotest.matchers.floats.shouldBeExactly18import io.kotest.matchers.ints.shouldBeExactly19import io.kotest.matchers.longs.shouldBeExactly20import io.kotest.matchers.nulls.shouldBeNull21import io.kotest.matchers.shouldBe22import io.kotest.matchers.types.shouldBeSameInstanceAs23class CoreTest : FreeSpec({24 "inc" {25 inc(1.toByte()) shouldBe 2.toByte()26 inc(1.toShort()) shouldBe 2.toShort()27 inc(1) shouldBeExactly 228 inc(1L) shouldBeExactly 2L29 inc(1.2f) shouldBeExactly 2.2f30 inc(1.2) shouldBeExactly 2.231 }32 "dec" {33 dec(1.toByte()) shouldBe 0.toByte()34 dec(1.toShort()) shouldBe 0.toShort()35 dec(1) shouldBeExactly 036 dec(1L) shouldBeExactly 0L37 dec(1.2f) shouldBeExactly 1.2f.dec()38 dec(1.2) shouldBeExactly 1.2.dec()39 }40 "`identity` should return x" {41 identity(10) shouldBeExactly 1042 identity(10.1) shouldBeExactly 10.143 identity("a") shouldBe "a"44 identity(true).shouldBeTrue()45 val f = {}46 identity(f) shouldBeSameInstanceAs f47 }48 "`str` should return the string value of the arg" {49 str() shouldBe ""50 str(null) shouldBe ""51 str(1) shouldBe "1"52 str(1, 2) shouldBe "12"53 str(1, 2, 3) shouldBe "123"54 str(1, null, 3) shouldBe "13"55 str(1, 2, null) shouldBe "12"56 str(null, 2, 3) shouldBe "23"57 str(1, 2, 3, 4) shouldBe "1234"58 }59 "curry" {60 val arg1 = 161 val arg2 = 1.062 val arg3 = 1.0F63 val arg4 = ""64 val arg5 = true65 val arg6 = 1L66 val f1 = { _: Int, _: Double -> 1 }67 val f2 = { _: Int, _: Double, _: Float -> 1 }68 val f3 = { _: Int, _: Double, _: Float, _: String -> 1 }69 val f4 = { _: Int, _: Double, _: Float, _: String, _: Boolean -> 1 }70 val f5 =71 { _: Int, _: Double, _: Float, _: String, _: Boolean, _: Long -> 1 }72 val curried1 = curry(f1)73 val curried2 = curry(f2)74 val curried3 = curry(f3)75 val curried4 = curry(f4)76 val curried5 = curry(f5)77 curried1(arg1)(arg2) shouldBeExactly f1(arg1, arg2)78 curried2(arg1)(arg2)(arg3) shouldBeExactly f2(arg1, arg2, arg3)79 curried3(arg1)(arg2)(arg3)(arg4) shouldBeExactly80 f3(arg1, arg2, arg3, arg4)81 curried4(arg1)(arg2)(arg3)(arg4)(arg5) shouldBeExactly82 f4(arg1, arg2, arg3, arg4, arg5)83 curried5(arg1)(arg2)(arg3)(arg4)(arg5)(arg6) shouldBeExactly84 f5(arg1, arg2, arg3, arg4, arg5, arg6)85 }86 "`complement` should return a function" {87 val f1 = { true }88 val f2 = { _: Int -> true }89 val f3 = { _: Int -> { _: Long -> true } }90 val f4 = { _: Int -> { _: Long -> { _: String -> true } } }91 val f5 = { _: Int ->92 { _: Long ->93 { _: String ->94 { _: Float ->95 true96 }97 }98 }99 }100 val complementF1 = complement(f1)101 val complementF2 = complement(f2)102 val complementF3 = complement(f3)103 val complementF4 = complement(f4)104 val complementF5 = complement(f5)105 complementF1() shouldBe false106 complementF2(0) shouldBe false107 complementF3(0)(0L) shouldBe false108 complementF4(0)(0L)("") shouldBe false109 complementF5(0)(0L)("")(1.2F) shouldBe false110 }111 "compose" - {112 "when it takes only one function f, it should return f" {113 val f: (Int) -> Int = ::identity114 compose<Int>() shouldBe ::identity115 compose(f) shouldBe f116 }117 "when g has no args, compose returns the composition with no args" {118 val f: (Int) -> String = { i: Int -> str(i) }119 val g: () -> Int = { 7 }120 val fog: () -> String = compose(f, g)121 fog() shouldBe f(g())122 }123 "when g has 1 arg, compose should return the composition with 1 arg" {124 val f: (Int) -> String = { i: Int -> str(i) }125 val g: (Float) -> Int = { 7 }126 val fog: (Float) -> String = compose(f, g)127 fog(1.2f) shouldBe f(g(1.2f))128 }129 "when g has 2 args, compose returns the composition with 2 args" {130 val x = 1.2f131 val y = 1.8132 val f: (Int) -> String = { i: Int -> str(i) }133 val g: (Float) -> (Double) -> Int = { { 7 } }134 val fog: (Float) -> (Double) -> String = compose(f, g)135 fog(x)(y) shouldBe f(g(x)(y))136 }137 "when g has 3 args, should return the composition with 3 args" {138 val x = 1.2f139 val y = 1.8140 val z = true141 val f: (Int) -> String = { i: Int -> str(i) }142 val g: (Float) -> (Double) -> (Boolean) -> Int = { { { 7 } } }143 val fog: (Float) -> (Double) -> (Boolean) -> String =144 compose(f, g)145 fog(x)(y)(z) shouldBe f(g(x)(y)(z))146 }147 }148 "ISeq component1() component2()" {149 val l = l(1, 2, 4)150 val (first, rest) = l151 first shouldBe l.first()152 rest shouldBe l.rest()153 }154 "assoc(map, key, val)" {155 assoc(null, ":a" to 15) shouldBe m(":a" to 15)156 assoc(m(":a" to 15), ":b" to 20) shouldBe m(":a" to 15, ":b" to 20)157 assoc(v(15, 56), 2 to 20) shouldBe v(15, 56, 20)158 }159 "assoc(map, key, val, kvs)" {160 val kvs: Array<Pair<String, Int>> = listOf<Pair<String, Int>>()161 .toTypedArray()162 assoc(null, ":a" to 15, *kvs) shouldBe m(":a" to 15)163 assoc(null, ":a" to 15, ":b" to 20) shouldBe m(":a" to 15, ":b" to 20)164 assoc(v(15, 56), 2 to 20, 3 to 45) shouldBe v(15, 56, 20, 45)165 }166 "assocIn(map, ks, v)" {167 assocIn(null, l(":a"), 22) shouldBe m(":a" to 22)168 assocIn(m(":a" to 11), l(":a"), 22) shouldBe m(":a" to 22)169 assocIn(v(41, 5, 6, 3), l(2), 22) shouldBe v(41, 5, 22, 3)170 assocIn(171 m(":a" to m(":b" to 45)),172 l(":a", ":b"),173 22174 ) shouldBe m(":a" to m(":b" to 22))175 assocIn(176 v(17, 21, v(3, 5, 6)),177 l(2, 1),178 22179 ) shouldBe v(17, 21, v(3, 22, 6))180 assocIn(181 m(":a" to m(":b" to 45)),182 l(":a", ":b"),183 m(":c" to 74)184 ) shouldBe m(":a" to m(":b" to m(":c" to 74)))185 }186 "toPmap() should return an instance of PersistentArrayMap" {187 val map = (1..8).associateWith { i -> "$i" }188 val pam: IPersistentMap<Int, String> = map.toPmap()189 (pam is PersistentArrayMap<*, *>).shouldBeTrue()190 }191 "toPmap() should return an instance of PersistentHashMap" {192 val map = (1..20).associateWith { "$it" }193 val pam: IPersistentMap<Int, String> = map.toPmap()194 (pam is PersistentHashMap<*, *>).shouldBeTrue()195 }196 "m()" {197 val arrayMap: IPersistentMap<String, Int> = m("a" to 1)198 val pairs = (1..20).map { Pair(it, "$it") }.toTypedArray()199 m<Int, Int>() shouldBeSameInstanceAs PersistentArrayMap.EmptyArrayMap200 (arrayMap is PersistentArrayMap<*, *>).shouldBeTrue()201 arrayMap.count shouldBeExactly 1202 arrayMap.containsKey("a").shouldBeTrue()203 shouldThrowExactly<IllegalArgumentException> {204 m("a" to 1, "b" to 2, "b" to 3)205 }.message shouldBe "Duplicate key: b"206 shouldThrowExactly<IllegalArgumentException> {207 m(*pairs.plus(Pair(1, "1")))208 }.message shouldBe "Duplicate key: 1"209 }210 "hashmap()" {211 val map = hashMap("a" to 1, "b" to 2, "c" to 3)212 val emptyMap = hashMap<String, Int>()213 emptyMap shouldBeSameInstanceAs PersistentHashMap.EmptyHashMap214 map.count shouldBeExactly 3215 map("a") shouldBe 1216 map("b") shouldBe 2217 map("c") shouldBe 3218 hashMap("b" to 2, "b" to 3) shouldBe hashMap("b" to 3)219 }220 "cons()" {221 cons(1, null) shouldBe l(1)222 cons(1, l(2, 3)) shouldBe l(1, 2, 3)223 cons(1, listOf(2, 3)) shouldBe l(1, 2, 3)224 cons(1, v(2, 3) as Seqable<*>) shouldBe l(1, 2, 3)225 cons(1, mapOf(2 to 3)) shouldBe l(1, MapEntry(2, 3))226 cons(1, intArrayOf(2, 3)) shouldBe l(1, 2, 3)227 cons(1, arrayOf('2', 3)) shouldBe l(1, '2', 3)228 cons(1, "abc") shouldBe l(1, 'a', 'b', 'c')229 }230 "v()" {231 v<Int>() shouldBeSameInstanceAs PersistentVector.EmptyVector232 v(1) shouldBe PersistentVector(1)233 v(1, 2) shouldBe PersistentVector(1, 2)234 v(1, 2, 3) shouldBe PersistentVector(1, 2, 3)235 v(1, 2, 3, 4) shouldBe PersistentVector(1, 2, 3, 4)236 v(1, 2, 3, 4, 5) shouldBe PersistentVector(1, 2, 3, 4, 5)237 v(1, 2, 3, 4, 5, 6) shouldBe PersistentVector(1, 2, 3, 4, 5, 6)238 v(1, 2, 3, 4, 5, 6, 7, 8) shouldBe239 PersistentVector(1, 2, 3, 4, 5, 6, 7, 8)240 }241 "IPersistentVector componentN()" {242 val (a, b, c, d, e, f) = v(1, 2, 3, 4, 5, 6)243 a shouldBeExactly 1244 b shouldBeExactly 2245 c shouldBeExactly 3246 d shouldBeExactly 4247 e shouldBeExactly 5248 f shouldBeExactly 6249 }250 "IPersistentVector get operator" {251 val vec = v(1, 2, 3)252 vec[0] shouldBeExactly 1253 vec[1] shouldBeExactly 2254 vec[2] shouldBeExactly 3255 }256 "IPersistentVector iterator()" {257 val vec = v(1, 2, 3)258 for ((i, n) in vec.withIndex())259 n shouldBeExactly vec[i]260 }261 "IPersistentMap iterator()" {262 val m = m(0 to 45, 1 to 55, 2 to 12)263 var i = 0264 for ((_, v) in m) {265 v shouldBeExactly m[i]!!266 i++267 }268 }269 "IPersistentMap get operator" {270 val m = m("a" to 1, "b" to 2, "c" to 3)271 m["a"] shouldBe 1272 m["b"] shouldBe 2273 m["c"] shouldBe 3274 m["d"].shouldBeNull()275 }276 "first()" {277 first<Int>(l(1, 2, 3)) shouldBe 1278 first<Int>(listOf(1, 2, 3)) shouldBe 1279 first<Int>(v(1, 2, 3)) shouldBe 1280 first<Int>(v<Int>()).shouldBeNull()281 first<Int>(null).shouldBeNull()282 }283 "consChunk(chunk, rest) should return rest" {284 val rest = l(1, 2)285 val r = consChunk(ArrayChunk(arrayOf()), rest)286 r shouldBeSameInstanceAs rest287 }288 "consChunk(chunk, rest) should return ChunkedSeq" {289 val cs = consChunk(ArrayChunk(arrayOf(1, 2)), l(3, 4))290 cs.count shouldBeExactly 4291 cs.toString() shouldBe "(1 2 3 4)"292 }293 "spread()" {294 spread(null).shouldBeNull()295 spread(arrayOf(listOf(1))) shouldBe l(1)296 spread(arrayOf(1, 2, 3, listOf(4))) shouldBe l(1, 2, 3, 4)297 }298 "isEvery(pred, coll)" {299 isEvery<Int>({ true }, null).shouldBeTrue()300 isEvery<Int>({ it % 2 == 0 }, arrayOf(2, 4, 6)).shouldBeTrue()301 isEvery<Int>({ it % 2 == 0 }, arrayOf(2, 4, 1)).shouldBeFalse()302 isEvery<Int>({ it % 2 == 0 }, arrayOf(2, 4, null)).shouldBeFalse()303 }304 "conj() adds elements to a collection" {305 conj(null, 2) shouldBe l(2)306 conj(v(1), 2) shouldBe v(1, 2)307 conj(v(1), 2, 3, 4) shouldBe v(1, 2, 3, 4)308 conj(v(1), null, 3, 4) shouldBe v(1, null, 3, 4)309 conj(null, 1, 3, 4) shouldBe v(4, 3, 1)310 }311 "concat()" {312 val c = concat<Int>()313 c.count shouldBeExactly 0314 c.toString() shouldBe "()"315 }316 "concat(x)" {317 val c = concat<Int>(l(1, 2))318 c.count shouldBeExactly 2319 c.toString() shouldBe "(1 2)"320 }321 "concat(x, y)" {322 val c = concat<Int>(l(1, 2), l(3, 4))323 c.count shouldBeExactly 4324 c.toString() shouldBe "(1 2 3 4)"325 concat<Int>(null, l(3, 4)).toString() shouldBe "(3 4)"326 concat<Int>(l(1, 2), null).toString() shouldBe "(1 2)"327 }328 "concat(x, y) a ChunkedSeq" {329 val chunk1 = ArrayChunk(arrayOf(1, 2))330 val concatenation = concat<Int>(ChunkedSeq(chunk1), l(3, 4))331 concatenation.count shouldBeExactly 4332 concatenation.toString() shouldBe "(1 2 3 4)"333 }334 "concat(x, y, zs)" {335 val concatenation = concat<Int>(l(1, 2), l(3, 4), l(5, 6))336 concatenation.count shouldBeExactly 6337 concatenation.toString() shouldBe "(1 2 3 4 5 6)"338 concat<Int>(l(1, 2), l(3, 4), null).toString() shouldBe "(1 2 3 4)"339 concat<Int>(null, l(3, 4), l(5, 6)).toString() shouldBe "(3 4 5 6)"340 concat<Int>(l(1, 2), null, l(5, 6)).toString() shouldBe "(1 2 5 6)"341 val ch1 = ArrayChunk(arrayOf(1, 2))342 val ch2 = ArrayChunk(arrayOf(3, 4))343 val concat = concat<Int>(ChunkedSeq(ch1), ChunkedSeq(ch2), l(5, 6))344 concat.toString() shouldBe "(1 2 3 4 5 6)"345 concat<Int>(l(1, 2), listOf(3, 4), listOf(5, 6)).toString() shouldBe346 "(1 2 3 4 5 6)"347 concat<Int>(listOf(1, 2), v(3, 4), listOf(5, 6)).toString() shouldBe348 "(1 2 3 4 5 6)"349 }350 "q should return a PersistentQueue" {351 q<Int>() shouldBeSameInstanceAs PersistentQueue<Int>()352 q<Int>(null) shouldBeSameInstanceAs PersistentQueue<Int>()353 q<Int>(l(1, 2, 3, 4)) shouldBe q<Int>().conj(1).conj(2).conj(3).conj(4)354 q<Int>(v(1, 2, 3, 4)) shouldBe q<Int>().conj(1).conj(2).conj(3).conj(4)355 q<Int>(listOf(1, 2)) shouldBe q<Int>().conj(1).conj(2)356 }357 "map()" - {358 "mapping f to one collection" {359 map<Int, String>(l<Int>()) { "${it * 2}" } shouldBe Empty360 map<Int, String>(l(1, 3, 2)) { "${it * 2}" } shouldBe361 l("2", "6", "4")362 map<Int, String>(listOf(1, 3)) { "${it * 3}" } shouldBe l("3", "9")363 var i = 0364 val lazySeq = map<Int, String>(listOf(1, 3, 4, 2)) {365 i++ // to prove laziness, f is applied as the element is needed366 "${it * 2}"367 }368 lazySeq.first() shouldBe "2"369 i shouldBeExactly 1370 }371 "mapping f to two collections" {372 map<Int, Int, Int>(l(3, 5), l(4, 2)) { i, j ->373 i + j374 } shouldBe l(7, 7)375 map<Int, Int, Int>(l(3, 5), l(4)) { i, j ->376 i + j377 } shouldBe l(7)378 map<Int, Float, String>(l(3, 5), l(4.1f, 2.3f)) { i, j ->379 "${i + j}"380 } shouldBe l("7.1", "7.3")381 }382 "mapping f to three collections" {383 map<Int, Int, Int, Int>(l(3, 5), l(4, 2), l(1, 1)) { i, j, k ->384 i + j + k385 } shouldBe l(8, 8)386 map<Int, Int, Int, Int>(l(3, 5), l(4), l(1, 1)) { i, j, k ->387 i + j + k388 } shouldBe l(8)389 map<Int, Float, Boolean, String>(390 l(3, 5),391 l(4.1f, 2.3f),392 l(true, false)393 ) { i, j, k ->394 "${i + j}$k"395 } shouldBe l("7.1true", "7.3false")396 }397 }398 "Collections.seq()" {399 listOf(1, 2, 3, 4).seq() shouldBe l(1, 2, 3, 4)400 arrayOf(1, 2, 3, 4).seq() shouldBe l(1, 2, 3, 4)401 arrayListOf(1, 2, 3, 4).seq() shouldBe l(1, 2, 3, 4)402 sequenceOf(1, 2, 3, 4).seq() shouldBe l(1, 2, 3, 4)403 "abcd".seq() shouldBe l('a', 'b', 'c', 'd')404 shortArrayOf(1, 2, 3, 4).seq() shouldBe l(1, 2, 3, 4)405 intArrayOf(1, 2, 3, 4).seq() shouldBe l(1, 2, 3, 4)406 floatArrayOf(1f, 2f, 3f, 4f).seq() shouldBe l(1f, 2f, 3f, 4f)407 doubleArrayOf(1.1, 2.4).seq() shouldBe l(1.1, 2.4)408 longArrayOf(1, 2, 3, 4).seq() shouldBe l(1, 2, 3, 4)409 byteArrayOf(1, 2, 3, 4).seq() shouldBe l<Byte>(1, 2, 3, 4)410 charArrayOf('a', 'b', 'c', 'd').seq() shouldBe l('a', 'b', 'c', 'd')411 booleanArrayOf(true, false).seq() shouldBe l(true, false)412 mapOf(1 to 2, 3 to 4).seq() shouldBe l(MapEntry(1, 2), MapEntry(3, 4))413 }414})...

Full Screen

Full Screen

TestGenerators.kt

Source:TestGenerators.kt Github

copy

Full Screen

1package edu.illinois.cs.cs125.jenisol.core2import edu.illinois.cs.cs125.jenisol.core.generators.Complexity3import edu.illinois.cs.cs125.jenisol.core.generators.Defaults4import edu.illinois.cs.cs125.jenisol.core.generators.TypeGenerator5import edu.illinois.cs.cs125.jenisol.core.generators.TypeParameterGenerator6import edu.illinois.cs.cs125.jenisol.core.generators.compareBoxed7import edu.illinois.cs.cs125.jenisol.core.generators.getArrayType8import edu.illinois.cs.cs125.jenisol.core.generators.product9import examples.generatortesting.TestGenerators10import io.kotest.core.spec.style.StringSpec11import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder12import io.kotest.matchers.collections.shouldHaveSize13import io.kotest.matchers.ints.shouldBeGreaterThan14import io.kotest.matchers.ints.shouldBeLessThanOrEqual15import io.kotest.matchers.shouldBe16import java.lang.reflect.Method17import java.lang.reflect.Type18import kotlin.math.pow19fun Array<Type>.compareBoxed(other: Array<Class<*>>) = when {20 size != other.size -> false21 else -> zip(other).all { (mine, other) -> (mine as Class<*>).compareBoxed(other) }22}23class TestGenerators : StringSpec(24 {25 "it should generate bytes properly" {26 methodNamed("testByte").also { method ->27 method.invoke(null, 0.toByte())28 method.testGenerator()29 }30 methodNamed("testBoxedByte").also { method ->31 method.invoke(null, null)32 method.invoke(null, 0.toByte())33 method.testGenerator()34 }35 }36 "it should generate shorts properly" {37 methodNamed("testShort").also { method ->38 method.invoke(null, 0.toShort())39 method.testGenerator()40 }41 methodNamed("testBoxedShort").also { method ->42 method.invoke(null, null)43 method.invoke(null, 0.toShort())44 method.testGenerator()45 }46 }47 "it should generate ints properly" {48 methodNamed("testInt").also { method ->49 method.invoke(null, 0)50 method.testGenerator()51 }52 methodNamed("testBoxedInt").also { method ->53 method.invoke(null, null)54 method.invoke(null, 0)55 method.testGenerator()56 }57 }58 "it should generate longs properly" {59 methodNamed("testLong").also { method ->60 method.invoke(null, 0.toLong())61 method.testGenerator()62 }63 methodNamed("testBoxedLong").also { method ->64 method.invoke(null, null)65 method.invoke(null, 0.toLong())66 method.testGenerator()67 }68 }69 "it should generate floats properly" {70 methodNamed("testFloat").also { method ->71 method.invoke(null, 0.0f)72 method.testGenerator()73 }74 methodNamed("testBoxedFloat").also { method ->75 method.invoke(null, null)76 method.invoke(null, 0.0f)77 method.testGenerator()78 }79 }80 "it should generate doubles properly" {81 methodNamed("testDouble").also { method ->82 method.invoke(null, 0.0)83 method.testGenerator()84 }85 methodNamed("testBoxedDouble").also { method ->86 method.invoke(null, null)87 method.invoke(null, 0.0)88 method.testGenerator()89 }90 }91 "it should generate booleans properly" {92 methodNamed("testBoolean").also { method ->93 method.invoke(null, true)94 method.testGenerator()95 }96 methodNamed("testBoxedBoolean").also { method ->97 method.invoke(null, null)98 method.invoke(null, true)99 method.testGenerator()100 }101 }102 "it should generate chars properly" {103 methodNamed("testChar").also { method ->104 method.invoke(null, '8')105 method.testGenerator()106 }107 methodNamed("testBoxedChar").also { method ->108 method.invoke(null, null)109 method.invoke(null, '8')110 method.testGenerator()111 }112 }113 "it should generate Strings properly" {114 methodNamed("testString").also { method ->115 method.invoke(null, null)116 method.invoke(null, "test")117 method.testGenerator()118 }119 }120 "it should generate Objects properly" {121 methodNamed("testObject").also { method ->122 method.invoke(null, null)123 method.invoke(null, Any())124 method.testGenerator()125 }126 }127 "it should generate arrays properly" {128 methodNamed("testIntArray").also { method ->129 method.invoke(null, null)130 method.invoke(null, intArrayOf())131 method.invoke(null, intArrayOf(1, 2, 4))132 method.testGenerator()133 }134 methodNamed("testLongArray").also { method ->135 method.invoke(null, null)136 method.invoke(null, longArrayOf())137 method.invoke(null, longArrayOf(1, 2, 4))138 method.testGenerator()139 }140 methodNamed("testStringArray").also { method ->141 method.invoke(null, null)142 method.invoke(null, arrayOf<String>())143 method.invoke(null, arrayOf("test", "test me"))144 method.testGenerator()145 }146 methodNamed("testIntArrayArray").also { method ->147 method.invoke(null, null)148 method.invoke(null, arrayOf(intArrayOf()))149 method.invoke(null, arrayOf(intArrayOf(1, 2, 3), intArrayOf(4, 5, 6)))150 method.testGenerator()151 }152 methodNamed("testStringArrayArray").also { method ->153 method.invoke(null, null)154 method.invoke(null, arrayOf(arrayOf("")))155 method.invoke(null, arrayOf(arrayOf("test", "me"), arrayOf("again")))156 method.testGenerator()157 }158 }159 "it should generate lists properly" {160 methodNamed("testIntegerList").also { method ->161 method.invoke(null, null)162 method.invoke(null, listOf<Int>())163 method.invoke(null, listOf(1, 2, 5))164 method.testGenerator()165 }166 }167 "it should generate sets properly" {168 methodNamed("testIntegerSet").also { method ->169 method.invoke(null, null)170 method.invoke(null, setOf<Int>())171 method.invoke(null, setOf(1, 2, 5))172 method.testGenerator()173 }174 }175 "it should generate nested arrays properly" {176 Defaults.create(Array<Array<IntArray>>::class.java).also { generator ->177 (0..128).map {178 @Suppress("UNCHECKED_CAST")179 generator.random(Complexity(Complexity.MIN), null)180 .let { it.solutionCopy as Array<Array<IntArray>> }.totalSize().also {181 it shouldBeGreaterThan 0182 it shouldBeLessThanOrEqual 8183 }184 }185 (0..128).map {186 @Suppress("UNCHECKED_CAST")187 generator.random(Complexity(Complexity.MAX), null)188 .let { it.solutionCopy as Array<Array<IntArray>> }.totalSize().also {189 it shouldBeGreaterThan 0190 it shouldBeLessThanOrEqual 1024191 }192 }193 }194 }195 "it should generate parameters properly" {196 methodNamed("testInt").testParameterGenerator(3, 2)197 methodNamed("testTwoInts").testParameterGenerator(3, 2, 2)198 methodNamed("testIntArray").testParameterGenerator(2, 1)199 methodNamed("testTwoIntArrays").testParameterGenerator(2, 1, 2)200 methodNamed("testIntAndBoolean").testParameterGenerator(3 * 2, 0, 1, 4)201 }202 "it should determine array enclosed types correctly" {203 IntArray::class.java.getArrayType() shouldBe Int::class.java204 Array<IntArray>::class.java.getArrayType() shouldBe Int::class.java205 Array<Array<IntArray>>::class.java.getArrayType() shouldBe Int::class.java206 Array<Array<Array<String>>>::class.java.getArrayType() shouldBe String::class.java207 }208 "cartesian product should work" {209 listOf(listOf(1, 2), setOf(3, 4)).product().also {210 it shouldHaveSize 4211 it shouldContainExactlyInAnyOrder setOf(listOf(1, 3), listOf(1, 4), listOf(2, 3), listOf(2, 4))212 }213 }214 @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")215 "boxed compare should work" {216 Int::class.java.compareBoxed(Integer::class.java) shouldBe true217 IntArray::class.java.compareBoxed(Array<Integer>::class.java) shouldBe true218 Array<IntArray>::class.java.compareBoxed(Array<Array<Integer>>::class.java) shouldBe true219 }220 "generated parameters should compare properly" {221 One(arrayOf(intArrayOf(1, 2, 3), intArrayOf(4, 5))).also {222 it shouldBe One(arrayOf(intArrayOf(1, 2, 3), intArrayOf(4, 5)))223 }224 Two(225 arrayOf(intArrayOf(1, 2, 3), intArrayOf(4, 5)),226 arrayOf(booleanArrayOf(true, false), booleanArrayOf(false, true))227 ).also {228 it shouldBe Two(229 arrayOf(intArrayOf(1, 2, 3), intArrayOf(4, 5)),230 arrayOf(booleanArrayOf(true, false), booleanArrayOf(false, true))231 )232 }233 }234 }235)236private fun methodNamed(name: String) = TestGenerators::class.java.declaredMethods237 .find { it.name == name } ?: error("Couldn't find method $name")238private fun Method.testGenerator(239 typeGenerator: TypeGenerator<*> = Defaults.create(this.genericParameterTypes.first())240) {241 typeGenerator.simple.forEach { invoke(null, it.solutionCopy) }242 typeGenerator.edge.forEach { invoke(null, it.solutionCopy) }243 (1..8).forEach { complexity ->244 repeat(4) { invoke(null, typeGenerator.random(Complexity(complexity), null).solutionCopy) }245 }246}247private fun Int.pow(exponent: Int) = toDouble().pow(exponent.toDouble()).toInt()248private fun Method.testParameterGenerator(249 simpleSize: Int,250 edgeSize: Int,251 dimensionality: Int = 1,252 mixedSize: Int = (simpleSize + edgeSize).pow(dimensionality) - simpleSize.pow(dimensionality) - edgeSize.pow(253 dimensionality254 )255) {256 val parameterGenerator =257 TypeParameterGenerator(parameters)258 parameterGenerator.simple.also { simple ->259 simple shouldHaveSize simpleSize.pow(dimensionality)260 simple.forEach { invoke(null, *it.solutionCopy) }261 }262 parameterGenerator.edge.also { edge ->263 edge shouldHaveSize edgeSize.pow(dimensionality)264 edge.forEach { invoke(null, *it.solutionCopy) }265 }266 parameterGenerator.mixed.also { mixed ->267 mixed shouldHaveSize mixedSize268 mixed.forEach { invoke(null, *it.solutionCopy) }269 }270 Complexity.ALL.forEach { complexity ->271 invoke(null, *parameterGenerator.random(complexity, null).solutionCopy)272 }273}274fun Array<Array<IntArray>>.totalSize() = size.let {275 var total = it276 total += getOrElse(0) { arrayOf() }.size277 total += getOrElse(0) { arrayOf() }.getOrElse(0) { intArrayOf() }.size278 total279}280@Suppress("unused")281fun Array<Array<IntArray>>.elementCount(): Int {282 var count = 0283 println(size)284 for (i in 0 until size) {285 println("$i:${get(i).size}")286 for (j in get(i).indices) {287 println("$i:$j:${get(i)[j].size}")288 count += get(i)[j].size289 }290 }291 return count292}...

Full Screen

Full Screen

TransactionsTest.kt

Source:TransactionsTest.kt Github

copy

Full Screen

1package io.blockfrost.sdk_kotlin.itests2import com.beust.klaxon.JsonObject3import io.blockfrost.sdk_kotlin.api.CardanoTransactionsApi4import io.blockfrost.sdk_kotlin.infrastructure.BadRequestException5import io.blockfrost.sdk_kotlin.infrastructure.BlockfrostConfig6import io.blockfrost.sdk_kotlin.models.TxContentOutputAmount7import io.blockfrost.sdk_kotlin.models.TxContentUtxoAmount8import io.blockfrost.sdk_kotlin.models.TxContentUtxoOutputs9import io.kotest.assertions.throwables.shouldThrowExactly10import io.kotest.core.spec.style.DescribeSpec11import io.kotest.matchers.collections.shouldNotBeEmpty12import io.kotest.matchers.floats.plusOrMinus13import io.kotest.matchers.nulls.shouldBeNull14import io.kotest.matchers.nulls.shouldNotBeNull15import io.kotest.matchers.shouldBe16import io.kotest.matchers.shouldNotBe17import kotlin.properties.Delegates18import kotlin.time.Duration19import kotlin.time.ExperimentalTime20@OptIn(ExperimentalTime::class)21class TransactionsTest : DescribeSpec({22 var api: CardanoTransactionsApi by Delegates.notNull()23 System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "INFO")24 describe("transactions"){25 beforeTest {26 api = CardanoTransactionsApi(config = BlockfrostConfig.defaulMainNetConfig)27 }28 it("byHash").config(timeout = Duration.Companion.seconds(10)){29 val r = api.getTransaction("28172ea876c3d1e691284e5179fae2feb3e69d7d41e43f8023dc380115741026")30 r.shouldNotBeNull()31 r.block.shouldBe("e6369fee087d31192016b1659f1c381e9fc4925339278a4eef6f340c96c1947f")32 r.blockHeight.shouldBe(5040611)33 r.index.shouldBe(0)34 r.outputAmount.shouldBe(listOf(TxContentOutputAmount("lovelace", "701374004958")))35 r.fees.shouldBe("874781")36 r.deposit.shouldBe("0")37 r.propertySize.shouldBe(16346)38 r.invalidBefore.shouldBe(null)39 r.invalidHereafter.shouldBe("15657684")40 r.utxoCount.shouldBe(80)41 r.withdrawalCount.shouldBe(0)42 r.delegationCount.shouldBe(0)43 r.stakeCertCount.shouldBe(0)44 r.poolUpdateCount.shouldBe(0)45 r.poolRetireCount.shouldBe(0)46 }47 it("utxos").config(timeout = Duration.Companion.seconds(10)){48 val r = api.getTransactionUtxos("927edb96f3386ab91b5f5d85d84cb4253c65b1c2f65fa7df25f81fab1d62987a")49 r.shouldNotBeNull()50 r.hash.shouldBe("927edb96f3386ab91b5f5d85d84cb4253c65b1c2f65fa7df25f81fab1d62987a")51 r.inputs.shouldBe(emptyList())52 r.outputs.shouldBe(listOf(53 TxContentUtxoOutputs("Ae2tdPwUPEZ9vtyppa1FdJzvqJZkEcXgdHxVYAzTWcPaoNycVq5rc36LC1S", listOf(54 TxContentUtxoAmount("lovelace", "538861000000")55 ))56 ))57 }58 it("withdrawals").config(timeout = Duration.Companion.seconds(10)){59 val r = api.getTransactionWithdrawals("9f811b021492a5544207f7b566b4e67c87f0918b9e7055ab3074d552ab18e895")60 r.shouldNotBeNull()61 r.shouldNotBeEmpty()62 r.size.shouldBe(1)63 r.forEach { it.shouldNotBeNull() }64 r[0].address.shouldBe("stake1ux77thpfertrfhkq3tlmssucn30ddvvn3s9fhvkvx7dd3msgmxve0")65 r[0].amount.shouldBe("7911187966")66 }67 it("mirs").config(timeout = Duration.Companion.seconds(10)){68 val r = api.getTransactionMirs("7b57f2cf1c442c563647ab29669c88b9116c2668d31d42526ff27ed614da1252")69 r.shouldNotBeNull()70 r.shouldNotBeEmpty()71 r.forEach { it.shouldNotBeNull() }72 }73 it("delegations").config(timeout = Duration.Companion.seconds(30)) {74 val r = api.getTransactionDelegations("c2120581050a1116ab38a5ac8a62d64df4cf12cf3370d22337201d36eb65fcc4")75 r.shouldNotBeNull()76 r.shouldNotBeEmpty()77 r.forEach { it.shouldNotBeNull() }78 r.size.shouldBe(1)79 r[0].certIndex.shouldBe(1)80 r[0].address.shouldBe("stake1uyhk4jwrrp683w8n9hutkddr0nns4nuun04m2x3a6v0s9cck0z4k9")81 r[0].poolId.shouldBe("pool1zgxvcqf0dvh0ze56ev2ayjvuex3zdd3hgxzdrcezkx497mv3l7s")82 }83 it("pool updates").config(timeout = Duration.Companion.seconds(30)) {84 val r = api.getTransactionPoolUpdates("28bd5e8c342ab89d6642e446cb299058ea36256af1718e4af9326898ce4192d7")85 r.shouldNotBeNull()86 r.shouldNotBeEmpty()87 r.forEach { it.shouldNotBeNull() }88 r.size.shouldBe(2)89 r[0].certIndex.shouldBe(0)90 r[0].poolId.shouldBe("pool1kchver88u3kygsak8wgll7htr8uxn5v35lfrsyy842nkscrzyvj")91 r[0].vrfKey.shouldBe("b4506cbdf5faeeb7bc771d0c17eea2e7e94749ec5a63e78a42d9ed8aad6baae5")92 r[0].pledge.shouldBe("100000000000")93 r[0].marginCost.shouldBe(0.018f.plusOrMinus(0.00001f))94 r[0].fixedCost.shouldBe("340000000")95 r[0].rewardAccount.shouldBe("stake1u97v0sjx96u5lydjfe2g5qdwkj6plm87h80q5vc0ma6wjpq22mh4c")96 r[0].owners.shouldBe(listOf("stake1ux69nctlngdhx99a6w8hrtexu89p9prqk8vmseg9qmmquyqhuns53"))97 @Suppress("UNCHECKED_CAST")98 val meta0: Map<String, Any?> = r[0].metadata as? Map<String, Any?> ?: throw RuntimeException("Could not get metadata")99 (meta0.getOrDefault("url", null) as? String?).shouldNotBeNull().shouldBe("https://stakhanovite.io/cardano/stkh-1.json")100 (meta0.getOrDefault("hash", null) as? String?).shouldNotBeNull().shouldBe("0f519c0478527c6fd05556ecb31fafe9e5a6b9861fac96f5935381b3e328ee5d")101 (meta0.getOrDefault("ticker", null) as? String?).shouldNotBeNull()102 (meta0.getOrDefault("description", null) as? String?).shouldNotBeNull()103 (meta0.getOrDefault("homepage", null) as? String?).shouldNotBeNull()104 r[0].relays.shouldNotBeNull()105 r[0].relays.shouldNotBeEmpty()106 @Suppress("UNCHECKED_CAST")107 val r0 = r[0].relays[0] as? Map<String, Any?> ?: throw RuntimeException("Could not get relays")108 (r0.getOrDefault("ipv4", null) as? String?).shouldBeNull()109 (r0.getOrDefault("ipv6", null) as? String?).shouldBeNull()110 (r0.getOrDefault("dns", null) as? String?).shouldNotBeNull().shouldBe("cardano-relay.stakhanovite.io")111 (r0.getOrDefault("dns_srv", null) as? String?).shouldBeNull()112 (r0.getOrDefault("port", null) as? Number?)?.toInt().shouldNotBeNull().shouldBe(7001)113 r[1].certIndex.shouldBe(1)114 r[1].poolId.shouldBe("pool1s7t7mfc89syw93h07aammaccnua66yn6d4l0mqt7zqurz2mczvq")115 r[1].vrfKey.shouldBe("f399304ca66731d66b739e4df6a94f32ab10b34450fb21b03720d2c1d45d59d2")116 r[1].pledge.shouldBe("10000000000")117 r[1].marginCost.shouldBe(0.018f.plusOrMinus(0.00001f))118 r[1].fixedCost.shouldBe("340000000")119 r[1].rewardAccount.shouldBe("stake1u97v0sjx96u5lydjfe2g5qdwkj6plm87h80q5vc0ma6wjpq22mh4c")120 r[1].owners.shouldBe(listOf("stake1uxclfpuwmmsdxjtqy7ee845246xlk6k4r5rxj6sexsh8caqf2z5dm"))121 @Suppress("UNCHECKED_CAST")122 val meta1: Map<String, Any?> = r[1].metadata as? Map<String, Any?> ?: throw RuntimeException("Could not get metadata")123 (meta1.getOrDefault("url", null) as? String?).shouldNotBeNull().shouldBe("https://stakhanovite.io/cardano/stkh-2.json")124 (meta1.getOrDefault("hash", null) as? String?).shouldNotBeNull().shouldBe("11171d873f8f5b704552111d75b629f840b1c3399b49d9642cf12970031583b7")125 (meta1.getOrDefault("ticker", null) as? String?).shouldBeNull()126 (meta1.getOrDefault("description", null) as? String?).shouldBeNull()127 (meta1.getOrDefault("homepage", null) as? String?).shouldBeNull()128 @Suppress("UNCHECKED_CAST")129 val r1 = r[1].relays[0] as? Map<String, Any?> ?: throw RuntimeException("Could not get relays")130 (r1.getOrDefault("ipv4", null) as? String?).shouldBeNull()131 (r1.getOrDefault("ipv6", null) as? String?).shouldBeNull()132 (r1.getOrDefault("dns", null) as? String?).shouldNotBeNull().shouldBe("cardano-relay.stakhanovite.io")133 (r1.getOrDefault("dns_srv", null) as? String?).shouldBeNull()134 (r1.getOrDefault("port", null) as? Number?)?.toInt().shouldNotBeNull().shouldBe(7001)135 }136 it("stakes").config(timeout = Duration.Companion.seconds(10)){137 val r = api.getTransactionStakes("c2120581050a1116ab38a5ac8a62d64df4cf12cf3370d22337201d36eb65fcc4")138 r.shouldNotBeNull()139 r.shouldNotBeEmpty()140 r.size.shouldBe(1)141 r.forEach { it.shouldNotBeNull() }142 r[0].certIndex.shouldBe(0)143 r[0].address.shouldBe("stake1uyhk4jwrrp683w8n9hutkddr0nns4nuun04m2x3a6v0s9cck0z4k9")144 r[0].registration.shouldBe(true)145 }146 it("pool retires").config(timeout = Duration.Companion.seconds(10)){147 val r = api.getTransactionPoolRetires("33770d42c7bc8a9a0bc9830ffb97941574dc61dc534796dd8614b99b6aadace4")148 r.shouldNotBeNull()149 r.shouldNotBeEmpty()150 r.size.shouldBe(1)151 r.forEach { it.shouldNotBeNull() }152 r[0].certIndex.shouldBe(0)153 r[0].poolId.shouldBe("pool1g36eg8e6tr6sur6y3cfpd8lglny3axh6pgka3acpnfyh22svdth")154 r[0].retiringEpoch.shouldBe(236)155 }156 it("metadata").config(timeout = Duration.Companion.seconds(40)){157 val r = api.getTransactionMetadata("e641005803337a553a03cf3c11a1819491a629bd7d0a3c39e4866a01b5dac36d")158 r.shouldNotBeNull()159 r.shouldNotBeEmpty()160 r.size.shouldBe(1)161 r.forEach { it.shouldNotBeNull() }162 r[0].label.shouldBe("1968")163 r[0].jsonMetadata.shouldBe(TestUtils.parseJson("""{"TSLA": [{"value": "865.85", "source": "investorsExchange"}], "DRAND": {"round": 492700, "randomness": "22966996b523a4726c3df9d7b8bae50230ef08a7452c53d64eacc2dad632afc5"}, "ADABTC": [{"value": "7.96e-06", "source": "coinGecko"}], "ADAEUR": [{"value": "0.260806", "source": "coinGecko"}], "ADAUSD": [{"value": "0.318835", "source": "coinGecko"}, {"value": "0.32190816861292343", "source": "ergoOracles"}], "AGIBTC": [{"value": "0.077643", "source": "coinGecko"}], "BTCUSD": [{"value": "40088", "source": "coinGecko"}], "ERGUSD": [{"value": "0.573205", "source": "coinGecko"}, {"value": "0.5728722202262749", "source": "ergoOracles"}], "BTCDIFF": [{"value": "20607418304385.63", "source": "blockBook"}]}""".trimIndent()) as JsonObject)164 r[0].jsonMetadata.shouldNotBe(TestUtils.parseJson("""{"TSLA": [{"value": "865.85", "source": "investxrsExchange"}], "DRAND": {"round": 492700, "randomness": "22966996b523a4726c3df9d7b8bae50230ef08a7452c53d64eacc2dad632afc5"}, "ADABTC": [{"value": "7.96e-06", "source": "coinGecko"}], "ADAEUR": [{"value": "0.260806", "source": "coinGecko"}], "ADAUSD": [{"value": "0.318835", "source": "coinGecko"}, {"value": "0.32190816861292343", "source": "ergoOracles"}], "AGIBTC": [{"value": "0.077643", "source": "coinGecko"}], "BTCUSD": [{"value": "40088", "source": "coinGecko"}], "ERGUSD": [{"value": "0.573205", "source": "coinGecko"}, {"value": "0.5728722202262749", "source": "ergoOracles"}], "BTCDIFF": [{"value": "20607418304385.63", "source": "blockBook"}]}""".trimIndent()) as JsonObject)165 }166 it("submit").config(timeout = Duration.Companion.seconds(10)){167 val dummyTx = "33770d42c7bc8a9a0bc9830ffb97941574dc61dc534796dd8614b99b6aadace4"168 shouldThrowExactly<BadRequestException> {169 api.submitTransaction(dummyTx.toByteArray())170 }171 }172 }173})...

Full Screen

Full Screen

TestExtension.kt

Source:TestExtension.kt Github

copy

Full Screen

1package io.github.config4k2import com.typesafe.config.Config3import com.typesafe.config.ConfigFactory4import com.typesafe.config.ConfigMemorySize5import com.typesafe.config.ConfigValue6import com.typesafe.config.ConfigValueType7import io.kotest.core.spec.style.WordSpec8import io.kotest.matchers.doubles.shouldBeExactly9import io.kotest.matchers.floats.shouldBeExactly10import io.kotest.matchers.shouldBe11import java.time.Duration12import java.time.Period13import java.time.temporal.TemporalAmount14class TestExtension : WordSpec({15 "Config.extract" should {16 "return Int value" {17 val num = 018 val config = ConfigFactory.parseString("""value = $num""")19 config.extract<Int>("value") shouldBe num20 }21 "return String value" {22 val str = "str"23 val config = ConfigFactory.parseString("""value = $str""")24 config.extract<String>("value") shouldBe str25 }26 "return Boolean value" {27 val b = true28 val config = ConfigFactory.parseString("""value = $b""")29 config.extract<Boolean>("value") shouldBe b30 }31 "return Double value" {32 val num = 0.133 val config = ConfigFactory.parseString("""value = $num""")34 config.extract<Double>("value") shouldBeExactly(num)35 }36 "return Float value" {37 val num = 0.1f38 val config = ConfigFactory.parseString("""value = $num""")39 config.extract<Float>("value") shouldBeExactly(num)40 }41 "return Long value" {42 val num = 1000L43 val config = ConfigFactory.parseString("""value = $num""")44 config.extract<Long>("value") shouldBe num45 }46 "return ConfigMemorySize" {47 val memorySize = "100KiB"48 val config = ConfigFactory.parseString("""value = $memorySize""")49 config.extract<ConfigMemorySize>("value") shouldBe50 ConfigMemorySize.ofBytes(100 * 1024)51 }52 "return Duration" {53 val duration = "60minutes"54 val config = ConfigFactory.parseString("""value = $duration""")55 config.extract<Duration>("value") shouldBe56 Duration.ofMinutes(60)57 }58 "return Period" {59 val period = "10years"60 val config = ConfigFactory.parseString("""value = $period""")61 config.extract<Period>("value") shouldBe62 Period.ofYears(10)63 }64 "return Regex" {65 val regex = ".*"66 val config = ConfigFactory.parseString("""value = "$regex"""")67 config.extract<Regex>("value").toString() shouldBe ".*"68 }69 "return TemporalAmount" {70 val temporalAmount = "5weeks"71 val config = ConfigFactory.parseString("""value = $temporalAmount""")72 config.extract<TemporalAmount>("value") shouldBe73 Period.ofWeeks(5)74 }75 "return Config" {76 val inner =77 """78 |{79 | field = value80 |}""".trimMargin()81 val config = ConfigFactory.parseString(82 """nest = $inner"""83 )84 config.extract<Config>(85 "nest"86 ) shouldBe ConfigFactory.parseString(inner)87 }88 "return ConfigValue" {89 val b = true90 val config = ConfigFactory.parseString("value = $b")91 val configValue = config.extract<ConfigValue>("value")92 configValue.valueType() shouldBe ConfigValueType.BOOLEAN93 configValue.unwrapped() shouldBe b94 }95 }96 "Config property delegate" should {97 "return Int value" {98 val num = 099 val config = ConfigFactory.parseString("""value = $num""")100 val value: Int by config101 value shouldBe num102 }103 "return String value" {104 val str = "str"105 val config = ConfigFactory.parseString("""value = $str""")106 val value: String by config107 value shouldBe str108 }109 "return Boolean value" {110 val b = true111 val config = ConfigFactory.parseString("""value = $b""")112 val value: Boolean by config113 value shouldBe b114 }115 "return Double value" {116 val num = 0.1117 val config = ConfigFactory.parseString("""value = $num""")118 val value: Double by config119 value shouldBe num120 }121 "return Float value" {122 val num = 0.1f123 val config = ConfigFactory.parseString("""value = $num""")124 val value: Float by config125 value shouldBe num126 }127 "return Long value" {128 val num = 1000L129 val config = ConfigFactory.parseString("""value = $num""")130 val value: Long by config131 value shouldBe num132 }133 "return ConfigMemorySize" {134 val memorySize = "100KiB"135 val config = ConfigFactory.parseString("""value = $memorySize""")136 val value: ConfigMemorySize by config137 value shouldBe ConfigMemorySize.ofBytes(100 * 1024)138 }139 "return Duration" {140 val duration = "60minutes"141 val config = ConfigFactory.parseString("""value = $duration""")142 val value: Duration by config143 value shouldBe Duration.ofMinutes(60)144 }145 "return Period" {146 val period = "10years"147 val config = ConfigFactory.parseString("""value = $period""")148 val value: Period by config149 value shouldBe Period.ofYears(10)150 }151 "return Regex" {152 val regex = ".*"153 val config = ConfigFactory.parseString("""value = "$regex"""")154 val value: Regex by config155 value.pattern shouldBe regex156 }157 "return TemporalAmount" {158 val temporalAmount = "5weeks"159 val config = ConfigFactory.parseString("""value = $temporalAmount""")160 val value: TemporalAmount by config161 value shouldBe Period.ofWeeks(5)162 }163 "return Config" {164 val inner =165 """166 |{167 | field = value168 |}""".trimMargin()169 val config = ConfigFactory.parseString(170 """nest = $inner"""171 )172 val nest: Config by config173 nest shouldBe ConfigFactory.parseString(inner)174 }175 "return ConfigValue" {176 val b = true177 val config = ConfigFactory.parseString("value = $b")178 val value: ConfigValue by config179 value.valueType() shouldBe ConfigValueType.BOOLEAN180 value.unwrapped() shouldBe b181 }182 }183})184fun String.toConfig(): Config = ConfigFactory.parseString(this.trimIndent())...

Full Screen

Full Screen

FloatMatchersTest.kt

Source:FloatMatchersTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.floats2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.floats.shouldBeExactly4import io.kotest.matchers.floats.shouldBeGreaterThan5import io.kotest.matchers.floats.shouldBeGreaterThanOrEqual6import io.kotest.matchers.floats.shouldBeLessThan7import io.kotest.matchers.floats.shouldBeLessThanOrEqual8import io.kotest.matchers.floats.shouldBeZero9import io.kotest.matchers.floats.shouldNotBeExactly10import io.kotest.matchers.floats.shouldNotBeGreaterThan11import io.kotest.matchers.floats.shouldNotBeGreaterThanOrEqual12import io.kotest.matchers.floats.shouldNotBeLessThan13import io.kotest.matchers.floats.shouldNotBeLessThanOrEqual14import io.kotest.matchers.floats.shouldNotBeZero15class FloatMatchersTest : StringSpec() {16 init {17 "shouldBeLessThan" {18 1f shouldBeLessThan 2f19 1.99999f shouldBeLessThan 2f20 Float.MIN_VALUE shouldBeLessThan Float.MAX_VALUE21 Float.NEGATIVE_INFINITY shouldBeLessThan Float.POSITIVE_INFINITY22 }23 "shouldBeLessThanOrEqual" {24 1f shouldBeLessThanOrEqual 2f25 1.5f shouldBeLessThanOrEqual 1.5f26 1f shouldBeLessThanOrEqual 1f27 2f shouldBeLessThanOrEqual 2f28 Float.MIN_VALUE shouldBeLessThanOrEqual Float.MAX_VALUE29 Float.MIN_VALUE shouldBeLessThanOrEqual Float.MIN_VALUE30 Float.MAX_VALUE shouldBeLessThanOrEqual Float.MAX_VALUE31 Float.NEGATIVE_INFINITY shouldBeLessThanOrEqual Float.POSITIVE_INFINITY32 }33 "shouldNotBeLessThan" {34 2f shouldNotBeLessThan 1f35 2f shouldNotBeLessThan 1.999f36 Float.MAX_VALUE shouldNotBeLessThan Float.MIN_VALUE37 Float.POSITIVE_INFINITY shouldNotBeLessThan Float.NEGATIVE_INFINITY38 }39 "shouldNotBeLessThanOrEqual" {40 2f shouldNotBeLessThanOrEqual 1f41 2.000001f shouldNotBeLessThanOrEqual 2f42 Float.MAX_VALUE shouldNotBeLessThanOrEqual Float.MIN_VALUE43 Float.POSITIVE_INFINITY shouldNotBeLessThanOrEqual Float.NEGATIVE_INFINITY44 }45 "shouldBeGreaterThan" {46 2f shouldBeGreaterThan 1f47 Float.MAX_VALUE shouldBeGreaterThan Float.MIN_VALUE48 Float.POSITIVE_INFINITY shouldBeGreaterThan Float.NEGATIVE_INFINITY49 }50 "shouldBeGreaterThanOrEqual" {51 2f shouldBeGreaterThanOrEqual 1f52 2f shouldBeGreaterThanOrEqual 2f53 1f shouldBeGreaterThanOrEqual 1f54 Float.MAX_VALUE shouldBeGreaterThanOrEqual Float.MIN_VALUE55 Float.MAX_VALUE shouldBeGreaterThanOrEqual Float.MAX_VALUE56 Float.MIN_VALUE shouldBeGreaterThanOrEqual Float.MIN_VALUE57 Float.POSITIVE_INFINITY shouldBeGreaterThanOrEqual Float.NEGATIVE_INFINITY58 }59 "shouldNotBeGreaterThan" {60 1f shouldNotBeGreaterThan 2f61 1.99999f shouldNotBeGreaterThan 2f62 Float.MIN_VALUE shouldNotBeGreaterThan Float.MAX_VALUE63 Float.NEGATIVE_INFINITY shouldNotBeGreaterThan Float.POSITIVE_INFINITY64 }65 "shouldNotBeGreaterThanOrEqual" {66 1f shouldNotBeGreaterThanOrEqual 2f67 1.99999f shouldNotBeGreaterThanOrEqual 2f68 Float.MIN_VALUE shouldNotBeGreaterThanOrEqual Float.MAX_VALUE69 Float.NEGATIVE_INFINITY shouldNotBeGreaterThanOrEqual Float.POSITIVE_INFINITY70 }71 "shouldBeExactly" {72 1f shouldBeExactly 1f73 -1f shouldBeExactly -1f74 0.00002f shouldBeExactly 0.00002f75 Float.MIN_VALUE shouldBeExactly Float.MIN_VALUE76 Float.MAX_VALUE shouldBeExactly Float.MAX_VALUE77 Float.POSITIVE_INFINITY shouldBeExactly Float.POSITIVE_INFINITY78 Float.NEGATIVE_INFINITY shouldBeExactly Float.NEGATIVE_INFINITY79 }80 "shouldNotBeExactly" {81 1f shouldNotBeExactly -1f82 1f shouldNotBeExactly 1.000001f83 1f shouldNotBeExactly 0.999999f84 Float.MIN_VALUE shouldNotBeExactly Float.MAX_VALUE85 Float.MIN_VALUE shouldNotBeExactly Float.NaN86 Float.MIN_VALUE shouldNotBeExactly Float.POSITIVE_INFINITY87 Float.MIN_VALUE shouldNotBeExactly Float.NEGATIVE_INFINITY88 Float.MAX_VALUE shouldNotBeExactly Float.MIN_VALUE89 Float.MAX_VALUE shouldNotBeExactly Float.NaN90 Float.MAX_VALUE shouldNotBeExactly Float.POSITIVE_INFINITY91 Float.MAX_VALUE shouldNotBeExactly Float.NEGATIVE_INFINITY92 }93 "shouldBeZero" {94 0f.shouldBeZero()95 }96 "shouldNotBeZero" {97 0.000001f.shouldNotBeZero()98 (-0.000001f).shouldNotBeZero()99 Float.MIN_VALUE.shouldNotBeZero()100 Float.MAX_VALUE.shouldNotBeZero()101 Float.NaN.shouldNotBeZero()102 Float.POSITIVE_INFINITY.shouldNotBeZero()103 Float.NEGATIVE_INFINITY.shouldNotBeZero()104 }105 }106}...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.shouldBe5import io.kotest.matchers.shouldNotBe6fun exactly(d: Float): Matcher<Float> = object : Matcher<Float> {7 override fun test(value: Float) = MatcherResult(value == d, "$value is not equal to expected value $d", "$value should not be equal to $d")8}9fun lt(x: Float) = beLessThan(x)10fun beLessThan(x: Float) = object : Matcher<Float> {11 override fun test(value: Float) = MatcherResult(value < x, "$value should be < $x", "$value should not be < $x")12}13fun lte(x: Float) = beLessThanOrEqualTo(x)14fun beLessThanOrEqualTo(x: Float) = object : Matcher<Float> {15 override fun test(value: Float) = MatcherResult(value <= x, "$value should be <= $x", "$value should not be <= $x")16}17fun gt(x: Float) = beGreaterThan(x)18fun beGreaterThan(x: Float) = object : Matcher<Float> {19 override fun test(value: Float) = MatcherResult(value > x, "$value should be > $x", "$value should not be > $x")20}21fun gte(x: Float) = beGreaterThanOrEqualTo(x)22fun beGreaterThanOrEqualTo(x: Float) = object : Matcher<Float> {23 override fun test(value: Float) = MatcherResult(value >= x, "$value should be >= $x", "$value should not be >= $x")24}25infix fun Float.shouldBeLessThan(x: Float) = this shouldBe lt(x)26infix fun Float.shouldNotBeLessThan(x: Float) = this shouldNotBe lt(x)27infix fun Float.shouldBeLessThanOrEqual(x: Float) = this shouldBe lte(x)28infix fun Float.shouldNotBeLessThanOrEqual(x: Float) = this shouldNotBe lte(x)29infix fun Float.shouldBeGreaterThan(x: Float) = this shouldBe gt(x)30infix fun Float.shouldNotBeGreaterThan(x: Float) = this shouldNotBe gt(x)31infix fun Float.shouldBeGreaterThanOrEqual(x: Float) = this shouldBe gte(x)32infix fun Float.shouldNotBeGreaterThanOrEqual(x: Float) = this shouldNotBe gte(x)33infix fun Float.shouldBeExactly(x: Float) = this shouldBe exactly(x)34infix fun Float.shouldNotBeExactly(x: Float) = this shouldNotBe exactly(x)35fun Float.shouldBeZero() = this shouldBeExactly 0f36fun Float.shouldNotBeZero() = this shouldNotBeExactly 0f...

Full Screen

Full Screen

IconGeneratorSpec.kt

Source:IconGeneratorSpec.kt Github

copy

Full Screen

1/*2 * Copyright 2022 Thibault Seisel3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.github.thibseisel.identikon.rendering17import io.kotest.core.spec.style.DescribeSpec18import io.kotest.matchers.floats.shouldBeBetween19import io.kotest.matchers.floats.shouldBeExactly20import io.kotest.matchers.ints.shouldBeBetween21import kotlin.random.Random22internal class IconGeneratorSpec : DescribeSpec({23 describe("The default hue generation algorithm") {24 val generator = IconGenerator()25 it("always computes hue in [0, 1]") {26 val randomBytes = generateRandomBytes()27 val hue: Float = generator.computeHue(randomBytes)28 hue.shouldBeBetween(0f, 1f, 0f)29 }30 it("returns 0 when bytes are all zero") {31 val bytes = ByteArray(4)32 val hue = generator.computeHue(bytes)33 hue.shouldBeExactly(0f)34 }35 }36 describe("The default octet selector algorithm") {37 val generator = IconGenerator()38 it("always returns a value in [0, 255]") {39 val bytes = byteArrayOf(-0xf, -0x7, 0x0, 0x7, 0xf)40 repeat(5) { index ->41 val octet = generator.getOctet(bytes, index)42 octet.shouldBeBetween(0, 255)43 }44 }45 }46})47private fun generateRandomBytes(): ByteArray {48 val bytes = ByteArray(8)49 return Random.nextBytes(bytes)50}...

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.floats.*2import io.kotest.matchers.ints.*3import io.kotest.matchers.longs.*4import io.kotest.matchers.shorts.*5import io.kotest.matchers.booleans.*6import io.kotest.matchers.chars.*7import io.kotest.matchers.bytes.*8import io.kotest.matchers.collections.*9import io.kotest.matchers.doubles.*10import io.kotest.matchers.floats.*11import io.kotest.matchers.ints.*12import io.kotest.matchers.longs.*13import io.kotest.matchers.shorts.*14import io.kotest.matchers.booleans.*15import io.kotest.matchers.chars.*16import io.kotest.matchers.bytes.*17import io.kotest.matchers.collections.*18import io.kotest.matchers.doubles.*

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.floats.beLessThan2 import io.kotest.matchers.floats.beGreaterThan3 import io.kotest.matchers.floats.beLessThanOrEqual4 import io.kotest.matchers.floats.beGreaterThanOrEqual5 import io.kotest.matchers.floats.beBetween6 import io.kotest.matchers.floats.beNegative7 import io.kotest.matchers.floats.bePositive8 import io.kotest.matchers.floats.beZero9 import io.kotest.matchers.floats.beNonZero10 import io.kotest.matchers.floats.beNaN11 import io.kotest.matchers.floats.beFinite12 import io.kotest.matchers.floats.beInfinite13 import io.kotest.matchers.floats.bePositiveInfinity14 import io.kotest.matchers.floats.beNegativeInfinity15 import io.kotest.matchers.floats.beCloseTo16 import io.kotest.matchers.floats.beExactly17 import io.kotest.matchers.floats.beWithin18 import io.kotest.matchers.floats.beExactlyOneOf19 import io.kotest.matchers.floats.beOneOf20 import io.kotest.matchers.floats.bePositiveOrZero21 import io.kotest.matchers.floats.beNegativeOrZero22 import io.kotest.matchers.floats.beGreaterThanOne23 import io.kotest.matchers.floats.beGreaterThanOrEqualToOne24 import io.kotest.matchers.floats.beLessThanOne25 import io.kotest.matchers.floats.beLessThanOrEqualToOne26 import io.kotest.matchers.floats.beZeroOrOne27 import io.kotest.matchers.floats.beNonZeroFloat28 import io.kotest.matchers.floats.beNonZeroDouble29 import io.kotest.matchers.longs.beLessThan30 import io.kotest.matchers.longs.beGreaterThan31 import io.kotest.matchers.longs.beLessThanOrEqual32 import io.kotest.matchers.longs.beGreaterThanOrEqual33 import io.kotest.matchers.longs.beBetween34 import io.kotest.matchers.longs.beNegative

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.floats.*2 import io.kotest.matchers.shouldBe3 import io.kotest.matchers.ints.*4 import io.kotest.matchers.shouldBe5 import io.kotest.matchers.longs.*6 import io.kotest.matchers.shouldBe7 import io.kotest.matchers.shorts.*8 import io.kotest.matchers.shouldBe9 import io.kotest.matchers.booleans.*10 import io.kotest.matchers.shouldBe11 import io.kotest.matchers.chars.*12 import io.kotest.matchers.shouldBe13 import io.kotest.matchers.doubles.*14 import io.kotest.matchers.shouldBe15 import io.kotest.matchers.bytes.*16 import io.kotest.matchers.shouldBe17 import io.kotest.matchers.collections.*18 import io.kotest.matchers.shouldBe19 import io.kotest.matchers.maps.*20 import io.kotest.matchers.shouldBe21 import io.kotest.matchers.sequences.*22 import io.kotest.matchers.shouldBe23 import io.kotest.matchers.nulls.*24 import io.kotest.matchers.shouldBe25 import io

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1assertEquals(1.0f, 1.0f)2assertEquals(1.0f, 1.0f)3assertEquals(1.0f, 1.0f)4assertEquals(1.0f, 1.0f)5assertEquals(1.0f, 1.0f)6assertEquals(1.0f, 1.0f)7assertEquals(1.0f, 1.0f)8assertEquals(1.0f, 1.0f)9assertEquals(1.0f, 1.0f)10assertEquals(1.0f, 1.0f)11assertEquals(1.0f, 1.0f)12assertEquals(1.0f, 1.0f)13assertEquals(1.0f, 1.0f)14assertEquals(1.0f, 1.0f

Full Screen

Full Screen

exactly

Using AI Code Generation

copy

Full Screen

1assertThat(1.1f).isCloseTo(1.0f, 0.1f)2assertThat(1).isExactly(1)3assertThat(1L).isExactly(1L)4assertThat(mapOf(1 to "one")).isExactly(mapOf(1 to "one"))5assertThat(1.toShort()).isExactly(1.toShort())6assertThat("one").isExactly("one")7assertThat("one").isExactly("one".toCharArray())8assertThat(true).isExactly(true)9assertThat('a').isExactly('a')10assertThat(1.1).isExactly(1.1)11assertThat(1.1f).isExactly(1.1f)12assertThat(1).isExactly(1)13assertThat(1L).isExactly(1L)14assertThat(mapOf(1 to "one")).isExactly(mapOf(1 to "one

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful