Skip to content

Commit 658323f

Browse files
Abduqodiri QurbonzodaSpace Team
authored andcommitted
Improve Array contentEquals and contentDeepEquals doc #KT-66896
1 parent 2a568be commit 658323f

File tree

14 files changed

+1087
-439
lines changed

14 files changed

+1087
-439
lines changed

kotlin-native/runtime/src/main/kotlin/generated/_ArraysNative.kt

Lines changed: 183 additions & 85 deletions
Large diffs are not rendered by default.

kotlin-native/runtime/src/main/kotlin/generated/_UArraysNative.kt

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,14 @@ public actual fun UShortArray.asList(): List<UShort> {
126126
}
127127

128128
/**
129-
* Returns `true` if the two specified arrays are *structurally* equal to one another,
130-
* i.e. contain the same number of the same elements in the same order.
129+
* Checks if the two specified arrays are *structurally* equal to one another.
130+
*
131+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
132+
*
133+
* @param other the array to compare with this array.
134+
* @return `true` if the two arrays are structurally equal, `false` otherwise.
135+
*
136+
* @sample samples.collections.Arrays.ContentOperations.intArrayContentEquals
131137
*/
132138
@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
133139
@SinceKotlin("1.3")
@@ -138,8 +144,14 @@ public infix fun UIntArray.contentEquals(other: UIntArray): Boolean {
138144
}
139145

140146
/**
141-
* Returns `true` if the two specified arrays are *structurally* equal to one another,
142-
* i.e. contain the same number of the same elements in the same order.
147+
* Checks if the two specified arrays are *structurally* equal to one another.
148+
*
149+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
150+
*
151+
* @param other the array to compare with this array.
152+
* @return `true` if the two arrays are structurally equal, `false` otherwise.
153+
*
154+
* @sample samples.collections.Arrays.ContentOperations.intArrayContentEquals
143155
*/
144156
@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
145157
@SinceKotlin("1.3")
@@ -150,8 +162,14 @@ public infix fun ULongArray.contentEquals(other: ULongArray): Boolean {
150162
}
151163

152164
/**
153-
* Returns `true` if the two specified arrays are *structurally* equal to one another,
154-
* i.e. contain the same number of the same elements in the same order.
165+
* Checks if the two specified arrays are *structurally* equal to one another.
166+
*
167+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
168+
*
169+
* @param other the array to compare with this array.
170+
* @return `true` if the two arrays are structurally equal, `false` otherwise.
171+
*
172+
* @sample samples.collections.Arrays.ContentOperations.intArrayContentEquals
155173
*/
156174
@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
157175
@SinceKotlin("1.3")
@@ -162,8 +180,14 @@ public infix fun UByteArray.contentEquals(other: UByteArray): Boolean {
162180
}
163181

164182
/**
165-
* Returns `true` if the two specified arrays are *structurally* equal to one another,
166-
* i.e. contain the same number of the same elements in the same order.
183+
* Checks if the two specified arrays are *structurally* equal to one another.
184+
*
185+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
186+
*
187+
* @param other the array to compare with this array.
188+
* @return `true` if the two arrays are structurally equal, `false` otherwise.
189+
*
190+
* @sample samples.collections.Arrays.ContentOperations.intArrayContentEquals
167191
*/
168192
@Deprecated("Use Kotlin compiler 1.4 to avoid deprecation warning.")
169193
@SinceKotlin("1.3")

libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,14 @@ public fun assertContains(charSequence: CharSequence, regex: Regex, message: Str
354354
}
355355

356356
/**
357-
* Asserts that the [expected] iterable is *structurally* equal to the [actual] iterable,
358-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
357+
* Asserts that the [expected] iterable is *structurally* equal to the [actual] iterable, with an optional [message].
359358
*
360-
* The elements are compared for equality with the [equals][Any.equals] function.
361-
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
359+
* Two iterables are considered structurally equal if they have the same size,
360+
* and elements at corresponding positions, following the iteration order, are equal.
361+
* Elements are compared for equality using the [equals][Any.equals] function.
362+
* For floating point numbers, this means `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
363+
*
364+
* The iterables are also considered equal if both are `null`.
362365
*/
363366
@SinceKotlin("1.5")
364367
public fun <@OnlyInputTypes T> assertContentEquals(expected: Iterable<T>?, actual: Iterable<T>?, message: String? = null) {
@@ -374,110 +377,140 @@ public fun <@OnlyInputTypes T> assertContentEquals(expected: Set<T>?, actual: Se
374377
assertContentEquals(expected, actual?.asIterable(), message)
375378

376379
/**
377-
* Asserts that the [expected] sequence is *structurally* equal to the [actual] sequence,
378-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
380+
* Asserts that the [expected] sequence is *structurally* equal to the [actual] sequence, with an optional [message].
381+
*
382+
* Two sequences are considered structurally equal if they have the same size,
383+
* and elements at corresponding positions, following the iteration order, are equal.
384+
* Elements are compared for equality using the [equals][Any.equals] function.
385+
* For floating point numbers, this means `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
379386
*
380-
* The elements are compared for equality with the [equals][Any.equals] function.
381-
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
387+
* The sequences are also considered equal if both are `null`.
382388
*/
383389
@SinceKotlin("1.5")
384390
public fun <@OnlyInputTypes T> assertContentEquals(expected: Sequence<T>?, actual: Sequence<T>?, message: String? = null) {
385391
assertIterableContentEquals("Sequence", message, expected, actual, Sequence<*>::iterator)
386392
}
387393

388394
/**
389-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
390-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
395+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
391396
*
392-
* The elements are compared for equality with the [equals][Any.equals] function.
393-
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
397+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
398+
* Elements are compared for equality using the [equals][Any.equals] function.
399+
* For floating point numbers, this means `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
400+
*
401+
* The arrays are also considered equal if both are `null`.
394402
*/
395403
@SinceKotlin("1.5")
396404
public fun <@OnlyInputTypes T> assertContentEquals(expected: Array<T>?, actual: Array<T>?, message: String? = null) {
397405
assertArrayContentEquals(message, expected, actual, { it.size }, Array<*>::get, Array<*>?::contentToString, Array<*>?::contentEquals)
398406
}
399407

400408
/**
401-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
402-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
409+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
410+
*
411+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
412+
*
413+
* The arrays are also considered equal if both are `null`.
403414
*/
404415
@SinceKotlin("1.5")
405416
public fun assertContentEquals(expected: ByteArray?, actual: ByteArray?, message: String? = null) {
406417
assertArrayContentEquals(message, expected, actual, { it.size }, ByteArray::get, ByteArray?::contentToString, ByteArray?::contentEquals)
407418
}
408419

409420
/**
410-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
411-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
421+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
422+
*
423+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
424+
*
425+
* The arrays are also considered equal if both are `null`.
412426
*/
413427
@SinceKotlin("1.5")
414428
public fun assertContentEquals(expected: ShortArray?, actual: ShortArray?, message: String? = null) {
415429
assertArrayContentEquals(message, expected, actual, { it.size }, ShortArray::get, ShortArray?::contentToString, ShortArray?::contentEquals)
416430
}
417431

418432
/**
419-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
420-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
433+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
434+
*
435+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
436+
*
437+
* The arrays are also considered equal if both are `null`.
421438
*/
422439
@SinceKotlin("1.5")
423440
public fun assertContentEquals(expected: IntArray?, actual: IntArray?, message: String? = null) {
424441
assertArrayContentEquals(message, expected, actual, { it.size }, IntArray::get, IntArray?::contentToString, IntArray?::contentEquals)
425442
}
426443

427444
/**
428-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
429-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
445+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
446+
*
447+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
448+
*
449+
* The arrays are also considered equal if both are `null`.
430450
*/
431451
@SinceKotlin("1.5")
432452
public fun assertContentEquals(expected: LongArray?, actual: LongArray?, message: String? = null) {
433453
assertArrayContentEquals(message, expected, actual, { it.size }, LongArray::get, LongArray?::contentToString, LongArray?::contentEquals)
434454
}
435455

436456
/**
437-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
438-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
457+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
458+
*
459+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
460+
* Elements are compared for equality using the [equals][Any.equals] function.
461+
* For floating point numbers, this means `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
439462
*
440-
* The elements are compared for equality with the [equals][Any.equals] function.
441-
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
463+
* The arrays are also considered equal if both are `null`.
442464
*/
443465
@SinceKotlin("1.5")
444466
public fun assertContentEquals(expected: FloatArray?, actual: FloatArray?, message: String? = null) {
445467
assertArrayContentEquals(message, expected, actual, { it.size }, FloatArray::get, FloatArray?::contentToString, FloatArray?::contentEquals)
446468
}
447469

448470
/**
449-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
450-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
471+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
472+
*
473+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
474+
* Elements are compared for equality using the [equals][Any.equals] function.
475+
* For floating point numbers, this means `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
451476
*
452-
* The elements are compared for equality with the [equals][Any.equals] function.
453-
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
477+
* The arrays are also considered equal if both are `null`.
454478
*/
455479
@SinceKotlin("1.5")
456480
public fun assertContentEquals(expected: DoubleArray?, actual: DoubleArray?, message: String? = null) {
457481
assertArrayContentEquals(message, expected, actual, { it.size }, DoubleArray::get, DoubleArray?::contentToString, DoubleArray?::contentEquals)
458482
}
459483

460484
/**
461-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
462-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
485+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
486+
*
487+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
488+
*
489+
* The arrays are also considered equal if both are `null`.
463490
*/
464491
@SinceKotlin("1.5")
465492
public fun assertContentEquals(expected: BooleanArray?, actual: BooleanArray?, message: String? = null) {
466493
assertArrayContentEquals(message, expected, actual, { it.size }, BooleanArray::get, BooleanArray?::contentToString, BooleanArray?::contentEquals)
467494
}
468495

469496
/**
470-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
471-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
497+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
498+
*
499+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
500+
*
501+
* The arrays are also considered equal if both are `null`.
472502
*/
473503
@SinceKotlin("1.5")
474504
public fun assertContentEquals(expected: CharArray?, actual: CharArray?, message: String? = null) {
475505
assertArrayContentEquals(message, expected, actual, { it.size }, CharArray::get, CharArray?::contentToString, CharArray?::contentEquals)
476506
}
477507

478508
/**
479-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
480-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
509+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
510+
*
511+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
512+
*
513+
* The arrays are also considered equal if both are `null`.
481514
*/
482515
@SinceKotlin("1.5")
483516
@OptIn(ExperimentalUnsignedTypes::class)
@@ -486,8 +519,11 @@ public fun assertContentEquals(expected: UByteArray?, actual: UByteArray?, messa
486519
}
487520

488521
/**
489-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
490-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
522+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
523+
*
524+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
525+
*
526+
* The arrays are also considered equal if both are `null`.
491527
*/
492528
@SinceKotlin("1.5")
493529
@OptIn(ExperimentalUnsignedTypes::class)
@@ -496,8 +532,11 @@ public fun assertContentEquals(expected: UShortArray?, actual: UShortArray?, mes
496532
}
497533

498534
/**
499-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
500-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
535+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
536+
*
537+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
538+
*
539+
* The arrays are also considered equal if both are `null`.
501540
*/
502541
@SinceKotlin("1.5")
503542
@OptIn(ExperimentalUnsignedTypes::class)
@@ -506,8 +545,11 @@ public fun assertContentEquals(expected: UIntArray?, actual: UIntArray?, message
506545
}
507546

508547
/**
509-
* Asserts that the [expected] array is *structurally* equal to the [actual] array,
510-
* i.e. contains the same number of the same elements in the same order, with an optional [message].
548+
* Asserts that the [expected] array is *structurally* equal to the [actual] array, with an optional [message].
549+
*
550+
* Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.
551+
*
552+
* The arrays are also considered equal if both are `null`.
511553
*/
512554
@SinceKotlin("1.5")
513555
@OptIn(ExperimentalUnsignedTypes::class)

0 commit comments

Comments
 (0)