forked from argotorg/fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_ops.fe
More file actions
64 lines (58 loc) · 1.23 KB
/
Copy patharray_ops.fe
File metadata and controls
64 lines (58 loc) · 1.23 KB
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
/// Test array creation, indexing, iteration, and mutation
#[test]
fn test_array_literal_sum() {
let arr: [u256; 5] = [10, 20, 30, 40, 50]
let mut sum: u256 = 0
for x in arr {
sum += x
}
assert!(sum == 150)
}
#[test]
fn test_array_index() {
let arr: [u256; 4] = [100, 200, 300, 400]
assert!(arr[0] == 100)
assert!(arr[1] == 200)
assert!(arr[2] == 300)
assert!(arr[3] == 400)
}
#[test]
fn test_array_mut() {
let mut arr: [u256; 3] = [1, 2, 3]
arr[1] = 99
assert!(arr[0] == 1)
assert!(arr[1] == 99)
assert!(arr[2] == 3)
}
#[test]
fn test_multiple_arrays() {
let a: [u256; 3] = [1, 2, 3]
let b: [u256; 3] = [10, 20, 30]
let mut sum: u256 = 0
for x in a {
sum += x
}
for x in b {
sum += x
}
assert!(sum == 66)
}
#[test]
fn test_u8_array_mut() {
let mut arr: [u8; 4] = [1, 2, 3, 4]
arr[1] = 9
assert!(arr[0] == 1)
assert!(arr[1] == 9)
assert!(arr[2] == 3)
assert!(arr[3] == 4)
}
#[test]
fn test_bool_array_mut() {
let mut arr: [bool; 4] = [true, false, true, false]
arr[1] = true
arr[2] = false
assert!(arr[0] == true)
assert!(arr[1] == true)
assert!(arr[2] == false)
assert!(arr[3] == false)
}