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