/ tests / tests / execution / array_of_optionals.adl
array_of_optionals.adl
 1  /*
 2  seed = 123456789
 3  
 4  [case]
 5  program = "test.alpha"
 6  function = "main"
 7  input = []
 8  */
 9  
10  program test.alpha {
11  
12      // Treat any 0-value as none for testing purposes
13      transition main() -> (u64, u64) {
14          let raw: [u64; 4] = [1, 0, 3, 0];
15          // Convert to optionals: 0u64 → none, otherwise Some(value)
16          let arr: [u64?; 4] = [
17              raw[0] == 0u64 ? none : raw[0],
18              raw[1] == 0u64 ? none : raw[1],
19              raw[2] == 0u64 ? none : raw[2],
20              raw[3] == 0u64 ? none : raw[3],
21          ];
22  
23          let sum: u64 = 0u64;
24          for i in 0u8..4u8 { // 1 + 2*2 + 3 + 4*4
25              sum += arr[i].unwrap_or((i * i) as u64);
26          }
27  
28          assert(sum == 14u64);
29  
30          return (sum, sum);
31      }
32  
33      @noupgrade
34      async constructor() {}
35  }