-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathResizeArrays.fs
148 lines (143 loc) · 9.43 KB
/
ResizeArrays.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
module DeepCopyResizeArrays
open System
open Fable.Pyxpecto
open DynamicObj
open Fable.Core
open TestUtils
let tests_DeepCopyResizeArrays = testList "ResizeArrays" [
testCase "bool" <| fun _ ->
let arr = ResizeArray([true; false])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- false
Expect.sequenceEqual original (ResizeArray([false; false])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([true; false])) "Clone should not be affected by original mutation"
testCase "byte" <| fun _ ->
let arr = ResizeArray([1uy; 2uy])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2uy
Expect.sequenceEqual original (ResizeArray([2uy; 2uy])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1uy; 2uy])) "Clone should not be affected by original mutation"
testCase "sbyte" <| fun _ ->
let arr = ResizeArray([1y; 2y])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2y
Expect.sequenceEqual original (ResizeArray([2y; 2y])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1y; 2y])) "Clone should not be affected by original mutation"
testCase "int16" <| fun _ ->
let arr = ResizeArray([1s; 2s])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2s
Expect.sequenceEqual original (ResizeArray([2s; 2s])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1s; 2s])) "Clone should not be affected by original mutation"
testCase "uint16" <| fun _ ->
let arr = ResizeArray([1us; 2us])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2us
Expect.sequenceEqual original (ResizeArray([2us; 2us])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1us; 2us])) "Clone should not be affected by original mutation"
testCase "int" <| fun _ ->
let arr = ResizeArray([1; 2])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2
Expect.sequenceEqual original (ResizeArray([2; 2])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1; 2])) "Clone should not be affected by original mutation"
testCase "uint" <| fun _ ->
let arr = ResizeArray([1u; 2u])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2u
Expect.sequenceEqual original (ResizeArray([2u; 2u])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1u; 2u])) "Clone should not be affected by original mutation"
testCase "int64" <| fun _ ->
let arr = ResizeArray([1L; 2L])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2L
Expect.sequenceEqual original (ResizeArray([2L; 2L])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1L; 2L])) "Clone should not be affected by original mutation"
testCase "uint64" <| fun _ ->
let arr = ResizeArray([1uL; 2uL])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2uL
Expect.sequenceEqual original (ResizeArray([2uL; 2uL])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1uL; 2uL])) "Clone should not be affected by original mutation"
testCase "float" <| fun _ ->
let arr = ResizeArray([1.0; 2.0])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2.0
Expect.sequenceEqual original (ResizeArray([2.0; 2.0])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1.0; 2.0])) "Clone should not be affected by original mutation"
testCase "float32" <| fun _ ->
let arr = ResizeArray([1.0f; 2.0f])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2.0f
Expect.sequenceEqual original (ResizeArray([2.0f; 2.0f])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1.0f; 2.0f])) "Clone should not be affected by original mutation"
testCase "char" <| fun _ ->
let arr = ResizeArray(['A'; 'B'])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 'B'
Expect.sequenceEqual original (ResizeArray(['B'; 'B'])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray(['A'; 'B'])) "Clone should not be affected by original mutation"
testCase "string" <| fun _ ->
let arr = ResizeArray(["Hi"; "Bye"])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- "Bye"
Expect.sequenceEqual original (ResizeArray(["Bye"; "Bye"])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray(["Hi"; "Bye"])) "Clone should not be affected by original mutation"
testCase "unit" <| fun _ ->
let arr = ResizeArray([(); ()])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
// transpilation fun
let arr2 = ResizeArray([()])
arr.Add(arr2[0])
Expect.sequenceEqual original (ResizeArray([(); (); ()])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([(); ()])) "Clone should not be affected by original mutation"
// some cases are not transpilable
#if !FABLE_COMPILER_PYTHON
testCase "decimal" <| fun _ ->
let arr = ResizeArray([1.0M; 2.0M])
let original, copy = constructDeepCopiedObj arr
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
arr[0] <- 2.0M
Expect.sequenceEqual original (ResizeArray([2.0M; 2.0M])) "Original schould have been mutated"
Expect.sequenceEqual copy (ResizeArray([1.0M; 2.0M])) "Clone should not be affected by original mutation"
#endif
#if !FABLE_COMPILER
testCase "nativeint" <| fun _ ->
let original, copy = constructDeepCopiedObj (ResizeArray([System.IntPtr(1); System.IntPtr(2)]))
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
testCase "unativeint" <| fun _ ->
let original, copy = constructDeepCopiedObj (ResizeArray([System.UIntPtr(1u); System.UIntPtr(2u)]))
Expect.sequenceEqual copy original "Expected values of copy and original to be equal"
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal"
#endif
]