How to use Long.shouldBeBetween method of io.kotest.matchers.longs.between class

Best Kotest code snippet using io.kotest.matchers.longs.between.Long.shouldBeBetween

DnsCacheManipulatorTests.kt

Source:DnsCacheManipulatorTests.kt Github

copy

Full Screen

1package com.alibaba.dcm2import com.alibaba.dcm.internal.JavaVersionUtil3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.AnnotationSpec5import io.kotest.matchers.collections.shouldBeEmpty6import io.kotest.matchers.collections.shouldContainExactly7import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder8import io.kotest.matchers.collections.shouldHaveSize9import io.kotest.matchers.longs.shouldBeBetween10import io.kotest.matchers.nulls.shouldBeNull11import io.kotest.matchers.shouldBe12import io.kotest.matchers.types.shouldNotBeSameInstanceAs13private const val IP1 = "42.42.42.1"14private const val IP2 = "42.42.42.2"15private const val IP3 = "42.42.42.3"16private const val IP4 = "42.42.42.4"17private const val DOMAIN_NOT_EXISTED = "www.domain-not-existed-2D4B2C4E-61D5-46B3-81FA-3A975156D1AE.com"18private const val EXISTED_DOMAIN = "bing.com"19private const val EXISTED_ANOTHER_DOMAIN = "www.bing.com"20/**21 * @author Jerry Lee (oldratlee at gmail dot com)22 */23class DnsCacheManipulatorTests : AnnotationSpec() {24 @BeforeAll25 fun beforeAll() {26 // System Properties27 // https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html28 println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")29 System.out.printf("Env info:%njava home: %s%njdk version: %s%n",30 System.getProperty("java.home"),31 System.getProperty("java.version"))32 println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")33 }34 @Before35 fun before() {36 DnsCacheManipulator.clearDnsCache()37 @Suppress("DEPRECATION")38 DnsCacheManipulator.getAllDnsCache().shouldBeEmpty()39 DnsCacheManipulator.listDnsNegativeCache().shouldBeEmpty()40 }41 ////////////////////////////////////////////////////////////////////42 // user case test43 ////////////////////////////////////////////////////////////////////44 @Test45 fun test_getDnsCache_null_ForNotExistedDomain() {46 val dnsCache = DnsCacheManipulator.getDnsCache(DOMAIN_NOT_EXISTED)47 dnsCache.shouldBeNull()48 }49 @Test50 fun test_getDnsCache_null_ForExistDomain_ButNotLookupYet() {51 val dnsCache = DnsCacheManipulator.getDnsCache(EXISTED_DOMAIN)52 dnsCache.shouldBeNull()53 }54 @Test55 fun test_setSingleIp() {56 val host = "single.ip.com"57 DnsCacheManipulator.setDnsCache(host, IP1)58 host.lookupIpByName() shouldBe IP159 host.lookupAllIps().shouldContainExactly(IP1)60 }61 @Test62 fun test_setDnsCache_multiIp() {63 val host = "multi.ip.com"64 val ips = arrayOf(IP1, IP2)65 DnsCacheManipulator.setDnsCache(host, *ips)66 host.lookupIpByName() shouldBe ips.first()67 // relookup the entry order may change68 host.lookupAllIps().shouldContainExactlyInAnyOrder(*ips)69 }70 @Test71 fun test_setDnsCache_getAllDnsCache() {72 val host = "www.test_setDnsCache_getAllDnsCache.com"73 DnsCacheManipulator.setDnsCache(host, IP1)74 @Suppress("DEPRECATION")75 val allDnsCacheEntries = DnsCacheManipulator.getAllDnsCache()76 allDnsCacheEntries shouldHaveSize 177 val expected = DnsCacheEntry(host, arrayOf(IP1), Long.MAX_VALUE)78 val actual = allDnsCacheEntries.first()79 actual shouldBeEqual expected80 val another = DnsCacheManipulator.getDnsCache(host)81 val another2 = DnsCacheManipulator.getDnsCache(host)82 // instance equals but NOT same83 another shouldBe actual84 another shouldNotBeSameInstanceAs actual85 another2 shouldBe another86 another2 shouldNotBeSameInstanceAs another87 // Check NegativeCache88 DnsCacheManipulator.listDnsNegativeCache().shouldBeEmpty()89 }90 @Test91 fun test_canSetExistedDomain_canExpire_thenReLookupBack() {92 val expected = EXISTED_DOMAIN.lookupAllIps()93 DnsCacheManipulator.setDnsCache(20, EXISTED_DOMAIN, IP1)94 EXISTED_DOMAIN.lookupIpByName() shouldBe IP195 Thread.sleep(40)96 // relookup the entry order may change97 EXISTED_DOMAIN.lookupAllIps() shouldContainExactlyInAnyOrder expected98 }99 @Test100 fun test_setNotExistedDomain_RemoveThenReLookupAndNotExisted() {101 DnsCacheManipulator.setDnsCache(DOMAIN_NOT_EXISTED, IP1)102 DOMAIN_NOT_EXISTED.lookupIpByName() shouldBe IP1103 DnsCacheManipulator.removeDnsCache(DOMAIN_NOT_EXISTED)104 DOMAIN_NOT_EXISTED.shouldBeNotExistedDomain()105 DnsCacheManipulator.listDnsCache().shouldBeEmpty()106 val negativeCache = DnsCacheManipulator.listDnsNegativeCache()107 negativeCache shouldHaveSize 1108 negativeCache.first().host shouldBeEqualAsHostName DOMAIN_NOT_EXISTED109 }110 @Test111 fun test_setNotExistedDomain_canExpire_thenReLookupAndNotExisted() {112 DnsCacheManipulator.setDnsCache(20, DOMAIN_NOT_EXISTED, IP1)113 val ip = DOMAIN_NOT_EXISTED.lookupIpByName()114 ip shouldBe IP1115 Thread.sleep(40)116 DOMAIN_NOT_EXISTED.shouldBeNotExistedDomain()117 DnsCacheManipulator.listDnsCache().shouldBeEmpty()118 val negativeCache = DnsCacheManipulator.listDnsNegativeCache()119 negativeCache shouldHaveSize 1120 negativeCache.first().host shouldBeEqualAsHostName DOMAIN_NOT_EXISTED121 }122 ////////////////////////////////////////////////////////////////////123 // test for CachePolicy124 ////////////////////////////////////////////////////////////////////125 @Test126 fun test_setDnsCachePolicy() {127 // trigger dns cache by lookup and clear, skip OS lookup time after,128 // otherwise the lookup operation time may take seconds.129 //130 // so reduce the lookup operation time,131 // make below time-tracking test code more stability132 skipOsLookupTimeAfterThenClear(EXISTED_DOMAIN, EXISTED_ANOTHER_DOMAIN)133 DnsCacheManipulator.setDnsCachePolicy(1)134 DnsCacheManipulator.getDnsCachePolicy() shouldBe 1135 //////////////////////////////////////////////////136 // 0. trigger dns cache by lookup137 //////////////////////////////////////////////////138 EXISTED_DOMAIN.lookupIpByName()139 val tick = System.currentTimeMillis()140 val dnsCacheEntry = DnsCacheManipulator.getDnsCache(EXISTED_DOMAIN)141 dnsCacheEntry!!.expiration.time.shouldBeBetween(tick, tick + 1020)142 //////////////////////////////////////////////////143 // 1. lookup before expire144 //////////////////////////////////////////////////145 Thread.sleep(500)146 EXISTED_DOMAIN.lookupIpByName()147 // get dns cache before expire148 DnsCacheManipulator.getDnsCache(EXISTED_DOMAIN) shouldBe dnsCacheEntry149 //////////////////////////////////////////////////150 // 2. get dns cache after expire151 //////////////////////////////////////////////////152 Thread.sleep(520)153 // return expired entry, because of no dns cache touch by external related operation!154 DnsCacheManipulator.getDnsCache(EXISTED_DOMAIN) shouldBe dnsCacheEntry155 //////////////////////////////////////////////////156 // 3. touch dns cache with external other host operation157 //////////////////////////////////////////////////158 EXISTED_ANOTHER_DOMAIN.lookupIpByName()159 DnsCacheManipulator.getDnsCache(EXISTED_DOMAIN).shouldBeNull()160 //////////////////////////////////////////////////161 // 4. relookup162 //////////////////////////////////////////////////163 EXISTED_DOMAIN.lookupIpByName()164 val relookupTick = System.currentTimeMillis()165 // get dns cache after expire166 val relookup = DnsCacheManipulator.getDnsCache(EXISTED_DOMAIN)167 relookup!!.expiration.time.shouldBeBetween(relookupTick, relookupTick + 1020)168 }169 @Test170 fun test_setNegativeDnsCachePolicy() {171 DnsCacheManipulator.setDnsNegativeCachePolicy(1)172 DnsCacheManipulator.getDnsNegativeCachePolicy() shouldBe 1173 //////////////////////////////////////////////////174 // 0. trigger dns cache by lookup175 //////////////////////////////////////////////////176 DOMAIN_NOT_EXISTED.shouldBeNotExistedDomain()177 val tick = System.currentTimeMillis()178 shouldContainOnlyOneNegativeCacheWitchExpirationBetween(tick, tick + 1020)179 //////////////////////////////////////////////////180 // 1. lookup before expire181 //////////////////////////////////////////////////182 Thread.sleep(500)183 DOMAIN_NOT_EXISTED.shouldBeNotExistedDomain()184 // get dns cache before expire185 shouldContainOnlyOneNegativeCacheWitchExpirationBetween(tick, tick + 1020)186 //////////////////////////////////////////////////187 // 2. get dns cache after expire188 //////////////////////////////////////////////////189 Thread.sleep(520)190 // get dns cache before expire191 shouldContainOnlyOneNegativeCacheWitchExpirationBetween(tick, tick + 1020)192 //////////////////////////////////////////////////193 // 3. touch dns cache with external other host operation194 //////////////////////////////////////////////////195 EXISTED_DOMAIN.lookupIpByName()196 if (JavaVersionUtil.isJavaVersionAtMost8()) {197 shouldContainOnlyOneNegativeCacheWitchExpirationBetween(tick, tick + 1020)198 } else {199 DnsCacheManipulator.listDnsNegativeCache().shouldBeEmpty()200 }201 //////////////////////////////////////////////////202 // 4. relookup203 //////////////////////////////////////////////////204 DOMAIN_NOT_EXISTED.shouldBeNotExistedDomain()205 val relookupTick = System.currentTimeMillis()206 shouldContainOnlyOneNegativeCacheWitchExpirationBetween(relookupTick, relookupTick + 1020)207 }208 ////////////////////////////////////////////////////////////////////209 // test for config file210 ////////////////////////////////////////////////////////////////////211 @Test212 fun test_loadDnsCacheConfig() {213 DnsCacheManipulator.loadDnsCacheConfig()214 val ip = "www.hello1.com".lookupIpByName()215 ip shouldBe IP1216 }217 @Test218 fun test_loadDnsCacheConfig_from_D_Option() {219 val key = "dcm.config.filename"220 try {221 System.setProperty(key, "customized-dns-cache.properties")222 DnsCacheManipulator.loadDnsCacheConfig()223 "www.customized.com".lookupIpByName() shouldBe IP2224 } finally {225 System.clearProperty(key)226 }227 }228 @Test229 fun test_loadDnsCacheConfig_fromMyConfig() {230 DnsCacheManipulator.loadDnsCacheConfig("my-dns-cache.properties")231 "www.hello2.com".lookupIpByName() shouldBe IP2232 }233 @Test234 fun test_multi_ips_in_config_file() {235 DnsCacheManipulator.loadDnsCacheConfig("dns-cache-multi-ips.properties")236 val host = "www.hello-multi-ips.com"237 val expected = DnsCacheEntry(host, arrayOf(IP1, IP2), Long.MAX_VALUE)238 val actual = DnsCacheManipulator.getDnsCache(host)239 actual shouldBeEqual expected240 val hostLoose = "www.hello-multi-ips-loose.com"241 val expectedLoose = DnsCacheEntry(hostLoose, arrayOf(IP1, IP2, IP3, IP4), Long.MAX_VALUE)242 val actualLoose = DnsCacheManipulator.getDnsCache(hostLoose)243 actualLoose shouldBeEqual expectedLoose244 }245 @Test246 fun test_configNotFound() {247 val ex = shouldThrow<DnsCacheManipulatorException> {248 DnsCacheManipulator.loadDnsCacheConfig("not-existed.properties")249 }250 ex.message shouldBe "Fail to find not-existed.properties on classpath!"251 }252}...

Full Screen

Full Screen

ProfiledConnectionPoolListenerTest.kt

Source:ProfiledConnectionPoolListenerTest.kt Github

copy

Full Screen

1package ru.fix.armeria.aggregating.profiler2import com.linecorp.armeria.client.ClientFactory3import com.linecorp.armeria.client.ConnectionPoolListener4import com.linecorp.armeria.client.WebClient5import com.linecorp.armeria.common.HttpResponse6import com.linecorp.armeria.common.HttpStatus7import com.linecorp.armeria.common.SessionProtocol8import io.kotest.assertions.assertSoftly9import io.kotest.assertions.timing.eventually10import io.kotest.matchers.longs.shouldBeBetween11import io.kotest.matchers.maps.shouldContainExactly12import io.kotest.matchers.nulls.shouldNotBeNull13import io.kotest.matchers.should14import io.kotest.matchers.shouldBe15import kotlinx.coroutines.future.await16import org.apache.logging.log4j.kotlin.Logging17import org.junit.jupiter.api.*18import ru.fix.aggregating.profiler.AggregatingProfiler19import ru.fix.armeria.aggregating.profiler.ProfilerTestUtils.EPOLL_SOCKET_CHANNEL20import ru.fix.armeria.aggregating.profiler.ProfilerTestUtils.indicatorWithNameEnding21import ru.fix.armeria.aggregating.profiler.ProfilerTestUtils.profiledCallReportWithNameEnding22import ru.fix.armeria.commons.testing.ArmeriaMockServer23import ru.fix.armeria.commons.testing.LocalHost24import java.time.Duration25import kotlin.time.ExperimentalTime26import kotlin.time.milliseconds27import kotlin.time.seconds28@ExperimentalTime29@TestInstance(TestInstance.Lifecycle.PER_CLASS)30internal class ProfiledConnectionPoolListenerTest {31 private val mockServer = ArmeriaMockServer()32 @BeforeAll33 suspend fun beforeAll() {34 mockServer.start()35 }36 @AfterAll37 suspend fun afterAll() {38 mockServer.stop()39 }40 @Test41 suspend fun `WHEN http_1_1 connection created and destroyed THEN its lifetime profiled AND connections count updated`() {42 `WHEN connection created and destroyed THEN its lifetime profiled AND connections count updated`(SessionProtocol.H1C)43 }44 @Test45 suspend fun `WHEN http_2 connection created and destroyed THEN its lifetime profiled AND connections count updated`() {46 `WHEN connection created and destroyed THEN its lifetime profiled AND connections count updated`(SessionProtocol.H2C)47 }48 private suspend fun `WHEN connection created and destroyed THEN its lifetime profiled AND connections count updated`(49 sessionProtocol: SessionProtocol50 ) {51 val profiler = AggregatingProfiler()52 val profilerReporter = profiler.createReporter()53 try {54 val connectionTtlMs: Long = 1.seconds.toLongMilliseconds()55 val client = WebClient56 .builder(mockServer.uri(sessionProtocol))57 .factory(58 ClientFactory.builder()59 .connectionPoolListener(60 ProfiledConnectionPoolListener(profiler, ConnectionPoolListener.noop())61 )62 .idleTimeout(Duration.ofMillis(connectionTtlMs))63 .build()64 ).build()65 mockServer.enqueue { HttpResponse.of(HttpStatus.OK) }66 val reportBeforeClientCall = profilerReporter.buildReportAndReset { metric, _ ->67 metric.name.endsWith(Metrics.ACTIVE_CHANNELS_COUNT)68 }69 client.get("/").aggregate().await()70 assertSoftly {71 reportBeforeClientCall.indicatorWithNameEnding(Metrics.ACTIVE_CHANNELS_COUNT) shouldBe 072 val report = profilerReporter.buildReportAndReset { metric, _ ->73 metric.name.endsWith(Metrics.CONNECTION_LIFETIME)74 }75 logger.trace { "$sessionProtocol Report: $report" }76 report.profiledCallReportWithNameEnding(Metrics.CONNECTION_LIFETIME)77 .should {78 it.shouldNotBeNull()79 it.identity.tags shouldContainExactly mapOf(80 MetricTags.REMOTE_HOST to LocalHost.HOSTNAME.value,81 MetricTags.REMOTE_ADDRESS to LocalHost.IP.value,82 MetricTags.REMOTE_PORT to mockServer.httpPort().toString(),83 MetricTags.PROTOCOL to sessionProtocol.uriText(),84 MetricTags.IS_MULTIPLEX_PROTOCOL to sessionProtocol.isMultiplex.toString(),85 MetricTags.CHANNEL_CLASS to EPOLL_SOCKET_CHANNEL86 )87 }88 }89 eventually((connectionTtlMs / 2).milliseconds) {90 val report = profilerReporter.buildReportAndReset { metric, _ ->91 metric.name.endsWith(Metrics.ACTIVE_CHANNELS_COUNT)92 }93 logger.trace { "$sessionProtocol Report: $report" }94 report.indicatorWithNameEnding(Metrics.ACTIVE_CHANNELS_COUNT) shouldBe 195 }96 /**97 * connection destroyed and:98 * - active_channels_count indicator decreased to 099 * - connection lifetime metric is profiled100 */101 eventually(2.seconds) {102 val report = profilerReporter.buildReportAndReset { metric, _ ->103 metric.name.endsWith(Metrics.ACTIVE_CHANNELS_COUNT)104 }105 logger.trace { "$sessionProtocol Report: $report" }106 report.indicatorWithNameEnding(Metrics.ACTIVE_CHANNELS_COUNT) shouldBe 0107 }108 eventually(1.seconds) {109 val report = profilerReporter.buildReportAndReset { metric, _ ->110 metric.name.endsWith(Metrics.CONNECTION_LIFETIME)111 }112 logger.trace { "$sessionProtocol Report: $report" }113 report.profiledCallReportWithNameEnding(Metrics.CONNECTION_LIFETIME).should {114 it.shouldNotBeNull()115 it.latencyMax.shouldBeBetween(116 (connectionTtlMs * 0.75).toLong(),117 connectionTtlMs * 3118 )119 }120 }121 } finally {122 logger.trace { "$sessionProtocol Final report: ${profilerReporter.buildReportAndReset()}" }123 }124 }125 companion object: Logging126}...

Full Screen

Full Screen

GooglePlayReviewRepositoryTest.kt

Source:GooglePlayReviewRepositoryTest.kt Github

copy

Full Screen

1package io.appvox.googleplay.review2import io.appvox.core.configuration.RequestConfiguration3import io.appvox.googleplay.BaseGooglePlayMockTest4import io.appvox.googleplay.review.GooglePlayReviewRepository.Companion.REQUEST_URL_DOMAIN5import io.appvox.googleplay.review.GooglePlayReviewRepository.Companion.REQUEST_URL_PATH6import io.appvox.googleplay.review.constant.GooglePlayLanguage7import io.appvox.googleplay.review.constant.GooglePlaySortType8import io.appvox.googleplay.review.domain.GooglePlayReviewRequestParameters9import io.appvox.core.review.ReviewRequest10import io.kotest.assertions.assertSoftly11import io.kotest.inspectors.forExactly12import io.kotest.matchers.ints.shouldBeBetween13import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual14import io.kotest.matchers.longs.shouldBeBetween15import io.kotest.matchers.string.shouldContain16import io.kotest.matchers.string.shouldNotBeEmpty17import io.kotest.matchers.string.shouldStartWith18import kotlinx.coroutines.ExperimentalCoroutinesApi19import org.junit.jupiter.params.ParameterizedTest20import org.junit.jupiter.params.provider.CsvSource21class GooglePlayReviewRepositoryTest : BaseGooglePlayMockTest() {22 private val repository = GooglePlayReviewRepository(RequestConfiguration(delay = 3000))23 @ExperimentalCoroutinesApi24 @ParameterizedTest25 @CsvSource(26 "com.twitter.android, en, 1, 40, 40"27 )28 fun `get Google Play reviews`(29 appId: String,30 language: String,31 sortType: Int,32 batchSize: Int,33 expectedReviewCount: Int34 ) {35 REQUEST_URL_DOMAIN = httpMockServerDomain36 val mockData = javaClass.getResource(37 "/review/com.twitter.android/relevant" +38 "/review_google_play_com.twitter.android_relevant_1.json"39 ).readText()40 stubHttpUrl(REQUEST_URL_PATH, mockData)41 val request = GooglePlayReviewRequestParameters(42 appId = appId,43 language = GooglePlayLanguage.fromValue(language),44 sortType = GooglePlaySortType.fromValue(sortType),45 batchSize = batchSize,46 fetchHistory = false47 )48 val response = repository.getReviewsByAppId(ReviewRequest(request))49 response.results?.forExactly(expectedReviewCount) { result ->50 assertSoftly(result) {51 reviewId shouldStartWith "gp:"52 userName.shouldNotBeEmpty()53 userProfilePicUrl shouldStartWith "https://play-lh.googleusercontent.com/"54 rating.shouldBeBetween(1, 5)55 userCommentText.shouldNotBeEmpty()56 userCommentTime.shouldBeBetween(0, Long.MAX_VALUE)57 likeCount.shouldBeGreaterThanOrEqual(0)58 reviewUrl shouldContain result.reviewId59 developerCommentText?.let { it.shouldNotBeEmpty() }60 developerCommentTime?.shouldBeBetween(0, Long.MAX_VALUE)61 }62 }63 response.nextToken.shouldNotBeEmpty()64 }65 @ExperimentalCoroutinesApi66 @ParameterizedTest67 @CsvSource(68 "com.twitter.android, " +69 "gp:AOqpTOFeIsixb5qcUUUvJLSz_JudDjdKvngeHbfbUNGh7ch4H3KYh6NFVObMQkdes5HXbLkp3x5iyEiyRsTpuw, " +70 "en, " +71 "40, " +72 "2"73 )74 fun `get Google Play review history`(75 appId: String,76 reviewId: String,77 language: String,78 batchSize: Int,79 expectedReviewCount: Int80 ) {81 REQUEST_URL_DOMAIN = httpMockServerDomain82 val mockData = javaClass.getResource(83 "/review/com.twitter.android/history" +84 "/review_google_play_com.twitter.android_history.json"85 ).readText()86 stubHttpUrl(REQUEST_URL_PATH, mockData)87 val request = GooglePlayReviewRequestParameters(88 appId = appId,89 language = GooglePlayLanguage.fromValue(language),90 // Sort Type is not used when fetching a review's history91 sortType = GooglePlaySortType.RECENT,92 batchSize = batchSize,93 fetchHistory = true94 )95 val response = repository.getReviewHistoryById(reviewId, ReviewRequest(request))96 response.forExactly(expectedReviewCount) { result ->97 assertSoftly(result) {98 reviewId shouldStartWith "gp:"99 userName.shouldNotBeEmpty()100 userProfilePicUrl shouldStartWith "https://play-lh.googleusercontent.com/"101 rating.shouldBeBetween(1, 5)102 userCommentText.shouldNotBeEmpty()103 userCommentTime.shouldBeBetween(0, Long.MAX_VALUE)104 likeCount.shouldBeGreaterThanOrEqual(0)105 reviewUrl shouldContain result.reviewId106 }107 }108 }109}...

Full Screen

Full Screen

LongTest.kt

Source:LongTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.property.arbitrary2import io.kotest.core.spec.style.FunSpec3import io.kotest.data.blocking.forAll4import io.kotest.data.row5import io.kotest.inspectors.forAll6import io.kotest.matchers.longs.shouldBeBetween7import io.kotest.matchers.shouldBe8import io.kotest.property.Arb9import io.kotest.property.arbitrary.edgecases10import io.kotest.property.arbitrary.long11import io.kotest.property.arbitrary.single12import io.kotest.property.arbitrary.uLong13import io.kotest.property.checkAll14import io.kotest.property.checkCoverage15class LongTest : FunSpec({16 test("<Long, Long> should give values between min and max inclusive") {17 // Test parameters include the test for negative bounds18 forAll(19 row(-10L, -1L),20 row(1L, 3L),21 row(-100L, 100L),22 row(Long.MAX_VALUE - 10L, Long.MAX_VALUE),23 row(Long.MIN_VALUE, Long.MIN_VALUE + 10L)24 ) { vMin, vMax ->25 val expectedValues = (vMin..vMax).toSet()26 val actualValues = (1..100_000).map { Arb.long(vMin, vMax).single() }.toSet()27 actualValues shouldBe expectedValues28 }29 }30 test("Arb.long edge cases should respect min and max bounds") {31 checkCoverage("run", 25.0) {32 checkAll<Long, Long> { min, max ->33 if (min < max) {34 classify("run")35 Arb.long(min..max).edgecases().forAll {36 it.shouldBeBetween(min, max)37 }38 }39 }40 }41 }42 test("Arb.long generates values in range") {43 val min = -140_737_488_355_328 // -2^4744 val max = 140_737_488_355_327 // 2^47 - 145 checkAll(100_000, Arb.long(min, max)) { value ->46 value.shouldBeBetween(min, max)47 }48 }49})50class ULongTest : FunSpec({51 test("<ULong, ULong> should give values between min and max inclusive") {52 forAll(53 row(1uL, 3uL),54 row(0uL, 100uL),55 row(ULong.MAX_VALUE - 10uL, ULong.MAX_VALUE),56 row(ULong.MIN_VALUE, ULong.MIN_VALUE + 10uL)57 ) { vMin, vMax ->58 val expectedValues = (vMin..vMax).toSet()59 val actualValues = (1..100_000).map { Arb.uLong(vMin, vMax).single() }.toSet()60 actualValues shouldBe expectedValues61 }62 }63 test("Arb.uLong edge cases should respect min and max bounds") {64 checkCoverage("run", 25.0) {65 checkAll<ULong, ULong> { min, max ->66 if (min < max) {67 classify("run")68 Arb.uLong(min..max).edgecases().forAll {69 it.shouldBeBetween(min, max)70 }71 }72 }73 }74 }75 test("Arb.uLong generates values in range") {76 val min = 0uL77 val max = 281_474_976_710_655u // 2^48 - 178 checkAll(100_000, Arb.uLong(min, max)) { value ->79 value.shouldBeBetween(min, max)80 }81 }82})...

Full Screen

Full Screen

Util.kt

Source:Util.kt Github

copy

Full Screen

1package com.alibaba.dcm2import com.alibaba.dcm.internal.JavaVersionUtil.isJavaVersionAtMost83import com.alibaba.dcm.internal.TestTimeUtil.NEVER_EXPIRATION_NANO_TIME_TO_TIME_MILLIS4import io.kotest.assertions.fail5import io.kotest.assertions.throwables.shouldThrow6import io.kotest.matchers.longs.shouldBeBetween7import io.kotest.matchers.shouldBe8import io.kotest.matchers.string.shouldBeEqualIgnoringCase9import java.net.InetAddress10import java.net.UnknownHostException11/**12 * @author Jerry Lee (oldratlee at gmail dot com)13 */14fun String.lookupIpByName(): String =15 InetAddress.getByName(this).hostAddress16fun String.lookupAllIps(): List<String> =17 InetAddress.getAllByName(this).map { it.hostAddress }18fun skipOsLookupTimeAfterThenClear(vararg domains: String) {19 for (domain in domains) {20 // trigger dns cache by lookup and clear, skip OS lookup time after21 domain.lookupIpByName()22 }23 DnsCacheManipulator.clearDnsCache()24}25fun String.shouldBeNotExistedDomain() {26 shouldThrow<UnknownHostException> {27 this.lookupIpByName()28 }29}30fun shouldContainOnlyOneNegativeCacheWitchExpirationBetween(start: Long, end: Long) {31 val negativeCache = DnsCacheManipulator.listDnsNegativeCache()32 negativeCache.size shouldBe 133 negativeCache.first().expiration.time.shouldBeBetween(start, end)34}35infix fun DnsCacheEntry?.shouldBeEqual(expected: DnsCacheEntry?) {36 if (this == null) {37 fail("actual DnsCacheEntry is null")38 }39 if (expected == null) {40 fail("expected DnsCacheEntry is null")41 }42 host shouldBeEqualAsHostName expected.host43 ips shouldBe expected.ips44 expiration.time shouldBeEqualAsExpiration expected.expiration.time45}46infix fun String.shouldBeEqualAsHostName(expected: String) {47 if (isJavaVersionAtMost8()) {48 // hard-coded test logic for jdk 8-49 // host name is unified to lower case by InetAddress50 this shouldBeEqualIgnoringCase expected51 } else {52 this shouldBe expected53 }54}55private infix fun Long.shouldBeEqualAsExpiration(expected: Long) {56 if (expected == Long.MAX_VALUE) {57 if (isJavaVersionAtMost8()) {58 this shouldBe expected59 } else {60 // hard-coded test logic for jdk 9+61 this.shouldBeEqualsWithTolerance(NEVER_EXPIRATION_NANO_TIME_TO_TIME_MILLIS, 5)62 }63 } else {64 this shouldBe expected65 }66}67private fun Long.shouldBeEqualsWithTolerance(expected: Long, tolerance: Long) {68 this.shouldBeBetween(expected - tolerance, expected + tolerance)69}...

Full Screen

Full Screen

RepeatWhileTest.kt

Source:RepeatWhileTest.kt Github

copy

Full Screen

1//package com.sksamuel.tabby.effects2//3//import io.kotest.core.spec.style.FunSpec4//import io.kotest.matchers.longs.shouldBeBetween5//import io.kotest.matchers.shouldBe6//import java.util.concurrent.atomic.AtomicInteger7//import kotlin.time.measureTime8//import kotlin.time.milliseconds9//10//class RepeatWhileTest : FunSpec() {11// init {12//13// test("IO.repeatWhile(schedule, predicate) should contine until predicate is false") {14// var counter = 015// IO { counter++ }.repeatWhile(Schedule.forever) { counter < 10 }.run()16// counter shouldBe 1017// }18//19// test("IO.repeatWhile(schedule, predicate) should contine until schedule expires") {20// val counter = AtomicInteger(0)21// IO { counter.incrementAndGet() }.repeatWhile(Schedule.iterations(5)) { counter.get() < 10 }.run()22// counter.get() shouldBe 623// }24//25// test("IO.repeatWhile(f) should contine while function returns a predicate") {26// measureTime {27// val counter = AtomicInteger(0)28// IO { counter.incrementAndGet() }.repeatWhile { if (it.index < 10) Schedule.delay(25.milliseconds) else Schedule.never }.run()29// counter.get() shouldBe 1130// }.toLongMilliseconds().shouldBeBetween(250, 325)31// }32// }33//}...

Full Screen

Full Screen

between.kt

Source:between.kt Github

copy

Full Screen

1package io.kotest.matchers.longs2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.shouldBe5import io.kotest.matchers.shouldNot6/**7 * Verifies that the given Long is between a and b inclusive.8 */9fun Long.shouldBeBetween(a: Long, b: Long) = this shouldBe between(a, b)10/**11 * Verifies that the given Long is NOT between a and b inclusive.12 */13fun Long.shouldNotBeBetween(a: Long, b: Long) = this shouldNot between(a, b)14/**15 * Verifies that the given Long is between a and b inclusive.16 */17fun between(a: Long, b: Long): Matcher<Long> = object : Matcher<Long> {18 override fun test(value: Long) = MatcherResult(value in a..b,19 "$value should be between ($a, $b)",20 "$value should not be between ($a, $b)")21}...

Full Screen

Full Screen

IsbnDtoTest.kt

Source:IsbnDtoTest.kt Github

copy

Full Screen

1package org.jesperancinha.spring2import io.kotest.matchers.collections.shouldHaveSize3import io.kotest.matchers.longs.shouldBeBetween4import org.junit.jupiter.api.Test5internal class IsbnDtoTest {6 @Test7 fun `should fall within ISBN 13 range`() {8 IsbnDto.ISBNS.shouldHaveSize(1_500_000)9 IsbnDto.ISBNS.forEach {10 it.Isbn.toLong().shouldBeBetween(1000000000000, 9999999999999)11 }12 }13}...

Full Screen

Full Screen

Long.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1 io.kotest.matchers.longs.between(0, 10)2 io.kotest.matchers.longs.greaterThanOrEqual(0)3 io.kotest.matchers.longs.greaterThan(0)4 io.kotest.matchers.longs.lessThanOrEqual(0)5 io.kotest.matchers.longs.lessThan(0)6 io.kotest.matchers.longs.negative()7 io.kotest.matchers.longs.positive()8 io.kotest.matchers.longs.zero()

Full Screen

Full Screen

Long.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1 1L.shouldBeBetween(0L, 2L)2 }3 fun `should use Long.shouldBeBetween method of io.kotest.matchers.longs.between class with message`() {4 1L.shouldBeBetween(0L, 2L, "1L should be between 0L and 2L")5 }6 fun `should use Long.shouldBeBetween method of io.kotest.matchers.longs.between class with message and lambda`() {7 1L.shouldBeBetween(0L, 2L, "1L should be between 0L and 2L") { "1L should be between 0L and 2L" }8 }9 fun `should use Long.shouldBeBetween method of io.kotest.matchers.longs.between class with lambda`() {10 1L.shouldBeBetween(0L, 2L) { "1L should be between 0L and 2L" }11 }12 fun `should use Long.shouldBeBetween method of io.kotest.matchers.longs.between class with range`() {13 1L.shouldBeBetween(0L..2L)14 }15 fun `should use Long.shouldBeBetween method of io.kotest.matchers.longs.between class with range with message`() {16 1L.shouldBeBetween(0L..2L, "1L should be between 0L and 2L")17 }18 fun `should use Long.shouldBeBetween method of io.kotest.matchers.longs.between class with range with message and lambda`() {

Full Screen

Full Screen

Long.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1 2 fun testLongShouldBeBetween() {2 4 a.shouldBeBetween(1L, 10L)3 5 }4 2 fun testLongShouldBeBetween() {5 4 a.shouldBeBetween(1L, 10L)6 5 }7 2 fun testLongShouldBeBetween() {8 4 a.shouldBeBetween(1L, 10L)9 5 }10 2 fun testLongShouldBeBetween() {11 4 a.shouldBeBetween(1L, 10L)12 5 }13 2 fun testLongShouldBeBetween() {14 4 a.shouldBeBetween(1L, 10L)15 5 }16 2 fun testLongShouldBeBetween() {17 4 a.shouldBeBetween(1L, 10L)18 5 }19 2 fun testLongShouldBeBetween() {20 4 a.shouldBeBetween(1L, 10L)21 5 }22 2 fun testLongShouldBeBetween() {23 4 a.shouldBeBetween(1L, 10L)24 5 }

Full Screen

Full Screen

Long.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1 1L.shouldBeBetween(0L, 2L)2 }3}4import io.kotest.mpp.bestName5import kotlin.reflect.KClass6 * forAll(Gen.int()) { a ->7 * }8 * val ints = Gen.int()9 * val evenInts = ints.map { it * 2 }10typealias Gen<A> = (RandomSource, GenSize) -> GenResult<A>

Full Screen

Full Screen

Long.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1 fun `test should be between`() {2 2L.shouldBeBetween(1L, 3L)3 }4 fun `test should be between`() {5 2L.shouldBeBetween(1L, 3L)6 }7 fun `test should be between`() {8 2L.shouldBeBetween(1L, 3L)9 }10 fun `test should be between`() {11 2L.shouldBeBetween(1L, 3L)12 }13 fun `test should be between`() {14 2L.shouldBeBetween(1L, 3L)15 }16 fun `test should be between`() {17 2L.shouldBeBetween(1L, 3L)18 }19 fun `test should be between`() {20 2L.shouldBeBetween(1L, 3L)21 }22 fun `test should be between`() {23 2L.shouldBeBetween(1L, 3L)24 }25 fun `test should be between`() {26 2L.shouldBeBetween(1L, 3L)

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