test: add multiple array clone tests
parent
e484fe15d3
commit
e41ddab3b0
|
@ -362,13 +362,45 @@ fn test_clone() {
|
|||
}
|
||||
|
||||
fn test_mutli_array_clone() {
|
||||
mut array1 := [[1, 2, 3], [4, 5, 6]]
|
||||
mut array2 := array1.clone()
|
||||
// 2d array_int
|
||||
mut a2_1 := [[1, 2, 3], [4, 5, 6]]
|
||||
mut a2_2 := a2_1.clone()
|
||||
|
||||
array1[0][1] = 0
|
||||
a2_1[0][1] = 0
|
||||
a2_2[1][0] = 0
|
||||
|
||||
assert array1 == [[1, 0, 3], [4, 5, 6]]
|
||||
assert array2 == [[1, 2, 3], [4, 5, 6]]
|
||||
assert a2_1 == [[1, 0, 3], [4, 5, 6]]
|
||||
assert a2_2 == [[1, 2, 3], [0, 5, 6]]
|
||||
|
||||
// 2d array_string
|
||||
mut b2_1 := [['1', '2', '3'], ['4', '5', '6']]
|
||||
mut b2_2 := b2_1.clone()
|
||||
|
||||
b2_1[0][1] = '0'
|
||||
b2_2[1][0] = '0'
|
||||
|
||||
assert b2_1 == [['1', '0', '3'], ['4', '5', '6']]
|
||||
assert b2_2 == [['1', '2', '3'], ['0', '5', '6']]
|
||||
|
||||
// 3d array_int
|
||||
mut a3_1 := [[[1,1], [2,2], [3,3]], [[4,4], [5,5], [6,6]]]
|
||||
mut a3_2 := a3_1.clone()
|
||||
|
||||
a3_1[0][0][1] = 0
|
||||
a3_2[0][1][0] = 0
|
||||
|
||||
assert a3_1 == [[[1, 0], [2, 2], [3, 3]], [[4, 4], [5, 5], [6, 6]]]
|
||||
assert a3_2 == [[[1, 1], [0, 2], [3, 3]], [[4, 4], [5, 5], [6, 6]]]
|
||||
|
||||
// 3d array_string
|
||||
mut b3_1 := [[['1','1'], ['2','2'], ['3','3']], [['4','4'], ['5','5'], ['6','6']]]
|
||||
mut b3_2 := b3_1.clone()
|
||||
|
||||
b3_1[0][0][1] = '0'
|
||||
b3_2[0][1][0] = '0'
|
||||
|
||||
assert b3_1 == [[['1','0'], ['2','2'], ['3','3']], [['4','4'], ['5','5'], ['6','6']]]
|
||||
assert b3_2 == [[['1','1'], ['0','2'], ['3','3']], [['4','4'], ['5','5'], ['6','6']]]
|
||||
}
|
||||
|
||||
fn test_doubling() {
|
||||
|
|
Loading…
Reference in New Issue