@@ -12,10 +12,7 @@ import io.kotest.matchers.booleans.shouldBeTrue
12
12
import io.kotest.matchers.nulls.shouldNotBeNull
13
13
import io.kotest.matchers.shouldBe
14
14
import io.kotest.property.Arb
15
- import io.kotest.property.arbitrary.boolean
16
- import io.kotest.property.arbitrary.int
17
- import io.kotest.property.arbitrary.negativeInt
18
- import io.kotest.property.arbitrary.pair
15
+ import io.kotest.property.arbitrary.*
19
16
import io.kotest.property.checkAll
20
17
import kotlin.math.max
21
18
import kotlin.math.min
@@ -445,4 +442,56 @@ class NonEmptyListTest : StringSpec({
445
442
}
446
443
}
447
444
}
445
+
446
+ " lastOrNull" {
447
+ checkAll(
448
+ Arb .nonEmptyList(Arb .int())
449
+ ) { a ->
450
+ val result = a.lastOrNull()
451
+ val expected = a.last()
452
+ result shouldBe expected
453
+ }
454
+ }
455
+
456
+ " extract" {
457
+ checkAll(
458
+ Arb .nonEmptyList(Arb .int())
459
+ ) { a ->
460
+ val result = a.extract()
461
+ val expected = a.head
462
+ result shouldBe expected
463
+ }
464
+ }
465
+
466
+ " plus" {
467
+ checkAll(
468
+ Arb .nonEmptyList(Arb .int()),
469
+ Arb .int()
470
+ ) { a, b ->
471
+ val result = a + b
472
+ val expected = a.all + b
473
+ result shouldBe expected
474
+ }
475
+ }
476
+
477
+ " coflatMap should retain the same length as the original list" {
478
+ checkAll(
479
+ Arb .nonEmptyList(Arb .int())
480
+ ) { a ->
481
+ val result = a.coflatMap { it.all }
482
+ val expected = a.all
483
+ result.size shouldBe expected.size
484
+ }
485
+ }
486
+
487
+ " foldLeft should sum up correctly for addition" {
488
+ checkAll(
489
+ Arb .nonEmptyList(Arb .int()),
490
+ Arb .int()
491
+ ) { list, initial ->
492
+ val result = list.foldLeft(initial) { acc, i -> acc + i }
493
+ val expected = initial + list.all.sum()
494
+ result shouldBe expected
495
+ }
496
+ }
448
497
})
0 commit comments