diff --git a/.tool-versions b/.tool-versions index 21cfc807..ebe25423 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.4.0 +scarb 2.5.3 diff --git a/Scarb.toml b/Scarb.toml index 3217d1f2..9f084f0b 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -19,7 +19,7 @@ description = "Community maintained Cairo and Starknet libraries" homepage = "https://github.com/keep-starknet-strange/alexandria/" [workspace.dependencies] -starknet = ">=2.4.0" +starknet = ">=2.5.3" [workspace.tool.fmt] sort-module-level-items = true diff --git a/src/ascii/src/integer.cairo b/src/ascii/src/integer.cairo index cdf45afb..ff911d09 100644 --- a/src/ascii/src/integer.cairo +++ b/src/ascii/src/integer.cairo @@ -36,10 +36,7 @@ impl ToAsciiArrayTraitImpl< } let mut num = self; - loop { - if num.is_zero() { - break; - } + while num.is_non_zero() { let (quotient, remainder) = DivRem::div_rem( num, TryInto::::try_into(10).unwrap().try_into().expect('Division by 0') ); @@ -153,10 +150,7 @@ impl U256ToAsciiArrayTraitImpl of ToAsciiArrayTrait { return new_arr; } let mut num = self; - loop { - if num.is_zero() { - break; - } + while num != 0 { let (quotient, remainder) = DivRem::div_rem( num, 10_u256.try_into().expect('Division by 0') ); diff --git a/src/ascii/src/tests/test_ascii_integer.cairo b/src/ascii/src/tests/test_ascii_integer.cairo index 417c0a1a..81928fa1 100644 --- a/src/ascii/src/tests/test_ascii_integer.cairo +++ b/src/ascii/src/tests/test_ascii_integer.cairo @@ -9,26 +9,26 @@ fn u256_to_ascii() { // 115792089237316195423570985008687907853269984665640564039457584007913129639935`. let num: u256 = BoundedInt::max(); let ascii: Array = num.to_ascii(); - assert(ascii.len() == 3, 'max u256 wrong len'); - assert(*ascii.at(0) == '1157920892373161954235709850086', 'max u256 wrong first felt'); - assert(*ascii.at(1) == '8790785326998466564056403945758', 'max u256 wrong second felt'); - assert(*ascii.at(2) == '4007913129639935', 'max u256 wrong third felt'); + assert_eq!(ascii.len(), 3, "max u256 wrong len"); + assert_eq!(*ascii.at(0), '1157920892373161954235709850086', "max u256 wrong first felt"); + assert_eq!(*ascii.at(1), '8790785326998466564056403945758', "max u256 wrong second felt"); + assert_eq!(*ascii.at(2), '4007913129639935', "max u256 wrong third felt"); // ------------------------------ min u256 test ----------------------------- // let num: u256 = BoundedInt::min(); let ascii: Array = num.to_ascii(); - assert(ascii.len() == 1, 'min u256 wrong len'); - assert(*ascii.at(0) == '0', 'min u256 wrong felt'); + assert_eq!(ascii.len(), 1, "min u256 wrong len"); + assert_eq!(*ascii.at(0), '0', "min u256 wrong felt"); // ---------------------------- 31 char u256 test --------------------------- // let ascii: Array = 1157920892373161954235709850086_u256.to_ascii(); - assert(ascii.len() == 1, 'u256 31 char wrong len'); - assert(*ascii.at(0) == '1157920892373161954235709850086', '31 char u256 wrong felt'); + assert_eq!(ascii.len(), 1, "u256 31 char wrong len"); + assert_eq!(*ascii.at(0), '1157920892373161954235709850086', "31 char u256 wrong felt"); // ---------------------------- 62 cahr u256 test --------------------------- // let ascii: Array = 11579208923731619542357098500868790785326998466564056403945758_u256 .to_ascii(); - assert(ascii.len() == 2, 'u256 31 char wrong len'); - assert(*ascii.at(0) == '1157920892373161954235709850086', '31 char u256 wrong felt'); - assert(*ascii.at(1) == '8790785326998466564056403945758', '62 char u256 wrong felt'); + assert_eq!(ascii.len(), 2, "u256 31 char wrong len"); + assert_eq!(*ascii.at(0), '1157920892373161954235709850086', "31 char u256 wrong felt"); + assert_eq!(*ascii.at(1), '8790785326998466564056403945758', "62 char u256 wrong felt"); } #[test] @@ -39,19 +39,19 @@ fn u128_to_ascii() { let num: u128 = BoundedInt::max(); let ascii: Array = num.to_ascii(); - assert(ascii.len() == 2, 'max u128 wrong len'); - assert(*ascii.at(0) == '3402823669209384634633746074317', 'max u128 wrong first felt'); - assert(*ascii.at(1) == '68211455', 'max u128 wrong second felt'); + assert_eq!(ascii.len(), 2, "max u128 wrong len"); + assert_eq!(*ascii.at(0), '3402823669209384634633746074317', "max u128 wrong first felt"); + assert_eq!(*ascii.at(1), '68211455', "max u128 wrong second felt"); // ------------------------------ min u128 test ----------------------------- // let num: u128 = BoundedInt::min(); let ascii: Array = num.to_ascii(); - assert(ascii.len() == 1, 'min u128 wrong len'); - assert(*ascii.at(0) == '0', 'min u128 wrong felt'); + assert_eq!(ascii.len(), 1, "min u128 wrong len"); + assert_eq!(*ascii.at(0), '0', "min u128 wrong felt"); // ---------------------------- 31 char u128 test --------------------------- // let ascii: Array = 3402823669209384634633746074317_u128.to_ascii(); - assert(ascii.len() == 1, 'u128 31 char wrong len'); - assert(*ascii.at(0) == '3402823669209384634633746074317', '31 char u128 wrong felt'); + assert_eq!(ascii.len(), 1, "u128 31 char wrong len"); + assert_eq!(*ascii.at(0), '3402823669209384634633746074317', "31 char u128 wrong felt"); } #[test] @@ -59,10 +59,10 @@ fn u128_to_ascii() { fn u64_to_ascii() { // ------------------------------ max u64 test ------------------------------ // let num: u64 = BoundedInt::max(); - assert(num.to_ascii() == '18446744073709551615', 'incorect u64 max felt'); + assert_eq!(num.to_ascii(), '18446744073709551615', "incorect u64 max felt"); // ------------------------------ min u64 test ------------------------------ // let num: u64 = BoundedInt::min(); - assert(num.to_ascii() == '0', 'incorect u64 min felt'); + assert_eq!(num.to_ascii(), '0', "incorect u64 min felt"); } #[test] @@ -70,10 +70,10 @@ fn u64_to_ascii() { fn u32_to_ascii() { // ------------------------------ max u32 test ------------------------------ // let num: u32 = BoundedInt::max(); - assert(num.to_ascii() == '4294967295', 'incorect u32 max felt'); + assert_eq!(num.to_ascii(), '4294967295', "incorect u32 max felt"); // ------------------------------ min u32 test ------------------------------ // let num: u32 = BoundedInt::min(); - assert(num.to_ascii() == '0', 'incorect u32 min felt'); + assert_eq!(num.to_ascii(), '0', "incorect u32 min felt"); } #[test] @@ -81,10 +81,10 @@ fn u32_to_ascii() { fn u16_to_ascii() { // ------------------------------ max u16 test ------------------------------ // let num: u16 = BoundedInt::max(); - assert(num.to_ascii() == '65535', 'incorect u16 max felt'); + assert_eq!(num.to_ascii(), '65535', "incorect u16 max felt"); // ------------------------------ min u16 test ------------------------------ // let num: u16 = BoundedInt::min(); - assert(num.to_ascii() == '0', 'incorect u16 min felt'); + assert_eq!(num.to_ascii(), '0', "incorect u16 min felt"); } #[test] @@ -92,8 +92,8 @@ fn u16_to_ascii() { fn u8_to_ascii() { // ------------------------------- max u8 test ------------------------------ // let num: u8 = BoundedInt::max(); - assert(num.to_ascii() == '255', 'incorect u8 max felt'); + assert_eq!(num.to_ascii(), '255', "incorect u8 max felt"); // ------------------------------- min u8 test ------------------------------ // let num: u8 = BoundedInt::min(); - assert(num.to_ascii() == '0', 'incorect u8 min felt'); + assert_eq!(num.to_ascii(), '0', "incorect u8 min felt"); } diff --git a/src/bytes/src/bytes.cairo b/src/bytes/src/bytes.cairo index f2255048..702bc146 100644 --- a/src/bytes/src/bytes.cairo +++ b/src/bytes/src/bytes.cairo @@ -127,10 +127,7 @@ impl BytesImpl of BytesTrait { data_len += 1; } - loop { - if data_len == 0 { - break; - }; + while data_len != 0 { data.append(0_u128); data_len -= 1; }; @@ -192,10 +189,8 @@ impl BytesImpl of BytesTrait { // if value in two elements, read them and join them let (element_index, element_offset) = BytesTrait::locate(offset); let value_in_one_element = element_offset + size <= BYTES_PER_ELEMENT; - let mut value = 0; - if value_in_one_element { - value = - read_sub_u128(*self.data[element_index], BYTES_PER_ELEMENT, element_offset, size); + let value = if value_in_one_element { + read_sub_u128(*self.data[element_index], BYTES_PER_ELEMENT, element_offset, size) } else { let (_, end_element_offset) = BytesTrait::locate(offset + size); let left = read_sub_u128( @@ -207,8 +202,8 @@ impl BytesImpl of BytesTrait { let right = read_sub_u128( *self.data[element_index + 1], BYTES_PER_ELEMENT, 0, end_element_offset ); - value = u128_join(left, right, end_element_offset); - } + u128_join(left, right, end_element_offset) + }; (offset + size, value) } @@ -223,14 +218,11 @@ impl BytesImpl of BytesTrait { } let mut offset = offset; let mut i = array_length; - loop { + while i != 0 { let (new_offset, value) = self.read_u128_packed(offset, element_size); array.append(value); offset = new_offset; i -= 1; - if i == 0 { - break; - }; }; (offset, array) } @@ -313,14 +305,11 @@ impl BytesImpl of BytesTrait { let mut offset = offset; let mut i = array_length; - loop { + while i != 0 { let (new_offset, value) = self.read_u256(offset); array.append(value); offset = new_offset; i -= 1; - if i == 0 { - break; - }; }; (offset, array) } @@ -339,10 +328,7 @@ impl BytesImpl of BytesTrait { // read full array element for sub_bytes let mut offset = offset; let mut sub_bytes_full_array_len = size / BYTES_PER_ELEMENT; - loop { - if sub_bytes_full_array_len == 0 { - break; - }; + while sub_bytes_full_array_len != 0 { let (new_offset, value) = self.read_u128(offset); array.append(value); offset = new_offset; @@ -477,10 +463,7 @@ impl BytesImpl of BytesTrait { // read full array element for other let mut offset = 0; let mut sub_bytes_full_array_len = *other.size / BYTES_PER_ELEMENT; - loop { - if sub_bytes_full_array_len == 0 { - break; - }; + while sub_bytes_full_array_len != 0 { let (new_offset, value) = other.read_u128(offset); self.append_u128(value); offset = new_offset; @@ -516,10 +499,7 @@ impl BytesImpl of BytesTrait { let mut hash_data: Array = array![]; let mut i: usize = 0; let mut offset: usize = 0; - loop { - if i == self.size() { - break; - } + while i != self.size() { let (new_offset, hash_data_item) = self.read_u8(offset); hash_data.append(hash_data_item); offset = new_offset; diff --git a/src/bytes/src/tests/test_bytes.cairo b/src/bytes/src/tests/test_bytes.cairo index 5674a9f1..08242c88 100644 --- a/src/bytes/src/tests/test_bytes.cairo +++ b/src/bytes/src/tests/test_bytes.cairo @@ -5,19 +5,19 @@ use starknet::ContractAddress; #[available_gas(20000000)] fn test_bytes_zero() { let bytes = BytesTrait::zero(1); - assert(bytes.size == 1, 'invalid size'); - assert(*bytes.data[0] == 0, 'invalid value'); + assert_eq!(bytes.size, 1, "invalid size"); + assert_eq!(*bytes.data[0], 0, "invalid value"); let bytes = BytesTrait::zero(17); - assert(bytes.size == 17, 'invalid size'); - assert(*bytes.data[0] == 0, 'invalid value'); - assert(*bytes.data[1] == 0, 'invalid value'); + assert_eq!(bytes.size, 17, "invalid size"); + assert_eq!(*bytes.data[0], 0, "invalid value"); + assert_eq!(*bytes.data[1], 0, "invalid value"); let (_, value) = bytes.read_u8(15); - assert(value == 0, 'invalid value'); + assert_eq!(value, 0, "invalid value"); let (_, value) = bytes.read_u8(0); - assert(value == 0, 'invalid value'); + assert_eq!(value, 0, "invalid value"); let (_, value) = bytes.read_u8(16); - assert(value == 0, 'invalid value'); + assert_eq!(value, 0, "invalid value"); } #[test] @@ -34,24 +34,24 @@ fn test_bytes_update() { let mut bytes = BytesTrait::new(5, array![0x01020304050000000000000000000000]); bytes.update_at(0, 0x05); - assert(bytes.size == 5, 'update_size1'); - assert(*bytes.data[0] == 0x05020304050000000000000000000000, 'update_value_1'); + assert_eq!(bytes.size, 5, "update_size1"); + assert_eq!(*bytes.data[0], 0x05020304050000000000000000000000, "update_value_1"); bytes.update_at(1, 0x06); - assert(bytes.size == 5, 'update_size2'); - assert(*bytes.data[0] == 0x05060304050000000000000000000000, 'update_value_2'); + assert_eq!(bytes.size, 5, "update_size2"); + assert_eq!(*bytes.data[0], 0x05060304050000000000000000000000, "update_value_2"); bytes.update_at(2, 0x07); - assert(bytes.size == 5, 'update_size3'); - assert(*bytes.data[0] == 0x05060704050000000000000000000000, 'update_value_3'); + assert_eq!(bytes.size, 5, "update_size3"); + assert_eq!(*bytes.data[0], 0x05060704050000000000000000000000, "update_value_3"); bytes.update_at(3, 0x08); - assert(bytes.size == 5, 'update_size4'); - assert(*bytes.data[0] == 0x05060708050000000000000000000000, 'update_value_4'); + assert_eq!(bytes.size, 5, "update_size4"); + assert_eq!(*bytes.data[0], 0x05060708050000000000000000000000, "update_value_4"); bytes.update_at(4, 0x09); - assert(bytes.size == 5, 'update_size5'); - assert(*bytes.data[0] == 0x05060708090000000000000000000000, 'update_value_5'); + assert_eq!(bytes.size, 5, "update_size5"); + assert_eq!(*bytes.data[0], 0x05060708090000000000000000000000, "update_value_5"); let mut bytes = BytesTrait::new( 42, @@ -63,22 +63,22 @@ fn test_bytes_update() { ); bytes.update_at(16, 0x16); - assert(bytes.size == 42, 'update_size6'); - assert(*bytes.data[0] == 0x01020304050607080910111213141516, 'update_value_6'); - assert(*bytes.data[1] == 0x16020304050607080910111213141516, 'update_value_7'); - assert(*bytes.data[2] == 0x01020304050607080910000000000000, 'update_value_8'); + assert_eq!(bytes.size, 42, "update_size6"); + assert_eq!(*bytes.data[0], 0x01020304050607080910111213141516, "update_value_6"); + assert_eq!(*bytes.data[1], 0x16020304050607080910111213141516, "update_value_7"); + assert_eq!(*bytes.data[2], 0x01020304050607080910000000000000, "update_value_8"); bytes.update_at(15, 0x01); - assert(bytes.size == 42, 'update_size7'); - assert(*bytes.data[0] == 0x01020304050607080910111213141501, 'update_value_9'); - assert(*bytes.data[1] == 0x16020304050607080910111213141516, 'update_value_10'); - assert(*bytes.data[2] == 0x01020304050607080910000000000000, 'update_value_11'); + assert_eq!(bytes.size, 42, "update_size7"); + assert_eq!(*bytes.data[0], 0x01020304050607080910111213141501, "update_value_9"); + assert_eq!(*bytes.data[1], 0x16020304050607080910111213141516, "update_value_10"); + assert_eq!(*bytes.data[2], 0x01020304050607080910000000000000, "update_value_11"); } #[test] #[available_gas(20000000)] fn test_bytes_read_u128_packed() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -87,31 +87,31 @@ fn test_bytes_read_u128_packed() { let bytes = BytesTrait::new(42, array); let (new_offset, value) = bytes.read_u128_packed(0, 1); - assert(new_offset == 1, 'read_u128_packed_1_offset'); - assert(value == 0x01, 'read_u128_packed_1_value'); + assert_eq!(new_offset, 1, "read_u128_packed_1_offset"); + assert_eq!(value, 0x01, "read_u128_packed_1_value"); let (new_offset, value) = bytes.read_u128_packed(new_offset, 14); - assert(new_offset == 15, 'read_u128_packed_2_offset'); - assert(value == 0x0203040506070809101112131415, 'read_u128_packed_2_value'); + assert_eq!(new_offset, 15, "read_u128_packed_2_offset"); + assert_eq!(value, 0x0203040506070809101112131415, "read_u128_packed_2_value"); let (new_offset, value) = bytes.read_u128_packed(new_offset, 15); - assert(new_offset == 30, 'read_u128_packed_3_offset'); - assert(value == 0x160102030405060708091011121314, 'read_u128_packed_3_value'); + assert_eq!(new_offset, 30, "read_u128_packed_3_offset"); + assert_eq!(value, 0x160102030405060708091011121314, "read_u128_packed_3_value"); let (new_offset, value) = bytes.read_u128_packed(new_offset, 8); - assert(new_offset == 38, 'read_u128_packed_4_offset'); - assert(value == 0x1516010203040506, 'read_u128_packed_4_value'); + assert_eq!(new_offset, 38, "read_u128_packed_4_offset"); + assert_eq!(value, 0x1516010203040506, "read_u128_packed_4_value"); let (new_offset, value) = bytes.read_u128_packed(new_offset, 4); - assert(new_offset == 42, 'read_u128_packed_5_offset'); - assert(value == 0x07080910, 'read_u128_packed_5_value'); + assert_eq!(new_offset, 42, "read_u128_packed_5_offset"); + assert_eq!(value, 0x07080910, "read_u128_packed_5_value"); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('out of bound',))] fn test_bytes_read_u128_packed_out_of_bound() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -126,7 +126,7 @@ fn test_bytes_read_u128_packed_out_of_bound() { #[available_gas(20000000)] #[should_panic(expected: ('too large',))] fn test_bytes_read_u128_packed_too_large() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -140,7 +140,7 @@ fn test_bytes_read_u128_packed_too_large() { #[test] #[available_gas(20000000)] fn test_bytes_read_u128_array_packed() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -149,24 +149,24 @@ fn test_bytes_read_u128_array_packed() { let bytes = BytesTrait::new(42, array); let (new_offset, new_array) = bytes.read_u128_array_packed(0, 3, 3); - assert(new_offset == 9, 'read_u128_array_1_offset'); - assert(*new_array[0] == 0x010203, 'read_u128_array_1_value_1'); - assert(*new_array[1] == 0x040506, 'read_u128_array_1_value_2'); - assert(*new_array[2] == 0x070809, 'read_u128_array_1_value_3'); + assert_eq!(new_offset, 9, "read_u128_array_1_offset"); + assert_eq!(*new_array[0], 0x010203, "read_u128_array_1_value_1"); + assert_eq!(*new_array[1], 0x040506, "read_u128_array_1_value_2"); + assert_eq!(*new_array[2], 0x070809, "read_u128_array_1_value_3"); let (new_offset, new_array) = bytes.read_u128_array_packed(9, 4, 7); - assert(new_offset == 37, 'read_u128_array_2_offset'); - assert(*new_array[0] == 0x10111213141516, 'read_u128_array_2_value_1'); - assert(*new_array[1] == 0x01020304050607, 'read_u128_array_2_value_2'); - assert(*new_array[2] == 0x08091011121314, 'read_u128_array_2_value_3'); - assert(*new_array[3] == 0x15160102030405, 'read_u128_array_2_value_4'); + assert_eq!(new_offset, 37, "read_u128_array_2_offset"); + assert_eq!(*new_array[0], 0x10111213141516, "read_u128_array_2_value_1"); + assert_eq!(*new_array[1], 0x01020304050607, "read_u128_array_2_value_2"); + assert_eq!(*new_array[2], 0x08091011121314, "read_u128_array_2_value_3"); + assert_eq!(*new_array[3], 0x15160102030405, "read_u128_array_2_value_4"); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('out of bound',))] fn test_bytes_read_u128_array_packed_out_of_bound() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -181,7 +181,7 @@ fn test_bytes_read_u128_array_packed_out_of_bound() { #[available_gas(20000000)] #[should_panic(expected: ('too large',))] fn test_bytes_read_u128_array_packed_too_large() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -195,7 +195,7 @@ fn test_bytes_read_u128_array_packed_too_large() { #[test] #[available_gas(20000000)] fn test_bytes_read_felt252_packed() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -204,15 +204,15 @@ fn test_bytes_read_felt252_packed() { let bytes = BytesTrait::new(42, array); let (new_offset, value) = bytes.read_felt252_packed(13, 20); - assert(new_offset == 33, 'read_felt252_1_offset'); - assert(value == 0x1415160102030405060708091011121314151601, 'read_felt252_1_value'); + assert_eq!(new_offset, 33, "read_felt252_1_offset"); + assert_eq!(value, 0x1415160102030405060708091011121314151601, "read_felt252_1_value"); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('out of bound',))] fn test_bytes_read_felt252_packed_out_of_bound() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -227,7 +227,7 @@ fn test_bytes_read_felt252_packed_out_of_bound() { #[available_gas(20000000)] #[should_panic(expected: ('too large',))] fn test_bytes_read_felt252_packed_too_large() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -241,7 +241,7 @@ fn test_bytes_read_felt252_packed_too_large() { #[test] #[available_gas(20000000)] fn test_bytes_read_u8() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -250,14 +250,14 @@ fn test_bytes_read_u8() { let bytes = BytesTrait::new(42, array); let (new_offset, value) = bytes.read_u8(15); - assert(new_offset == 16, 'read_u8_offset'); - assert(value == 0x16, 'read_u8_value'); + assert_eq!(new_offset, 16, "read_u8_offset"); + assert_eq!(value, 0x16, "read_u8_value"); } #[test] #[available_gas(20000000)] fn test_bytes_read_u16() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -266,14 +266,14 @@ fn test_bytes_read_u16() { let bytes = BytesTrait::new(42, array); let (new_offset, value) = bytes.read_u16(15); - assert(new_offset == 17, 'read_u16_offset'); - assert(value == 0x1601, 'read_u16_value'); + assert_eq!(new_offset, 17, "read_u16_offset"); + assert_eq!(value, 0x1601, "read_u16_value"); } #[test] #[available_gas(20000000)] fn test_bytes_read_u32() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -282,14 +282,14 @@ fn test_bytes_read_u32() { let bytes = BytesTrait::new(42, array); let (new_offset, value) = bytes.read_u32(15); - assert(new_offset == 19, 'read_u32_offset'); - assert(value == 0x16010203, 'read_u32_value'); + assert_eq!(new_offset, 19, "read_u32_offset"); + assert_eq!(value, 0x16010203, "read_u32_value"); } #[test] #[available_gas(20000000)] fn test_bytes_read_usize() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -298,14 +298,14 @@ fn test_bytes_read_usize() { let bytes = BytesTrait::new(42, array); let (new_offset, value) = bytes.read_usize(15); - assert(new_offset == 19, 'read_usize_offset'); - assert(value == 0x16010203, 'read_usize_value'); + assert_eq!(new_offset, 19, "read_usize_offset"); + assert_eq!(value, 0x16010203, "read_usize_value"); } #[test] #[available_gas(20000000)] fn test_bytes_read_u64() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -314,14 +314,14 @@ fn test_bytes_read_u64() { let bytes = BytesTrait::new(42, array); let (new_offset, value) = bytes.read_u64(15); - assert(new_offset == 23, 'read_u64_offset'); - assert(value == 0x1601020304050607, 'read_u64_value'); + assert_eq!(new_offset, 23, "read_u64_offset"); + assert_eq!(value, 0x1601020304050607, "read_u64_value"); } #[test] #[available_gas(20000000)] fn test_bytes_read_u128() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -330,14 +330,14 @@ fn test_bytes_read_u128() { let bytes = BytesTrait::new(42, array); let (new_offset, value) = bytes.read_u128(15); - assert(new_offset == 31, 'read_u128_offset'); - assert(value == 0x16010203040506070809101112131415, 'read_u128_value'); + assert_eq!(new_offset, 31, "read_u128_offset"); + assert_eq!(value, 0x16010203040506070809101112131415, "read_u128_value"); } #[test] #[available_gas(20000000)] fn test_bytes_read_u256() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, 0x01020304050607080910000000000000 @@ -346,15 +346,15 @@ fn test_bytes_read_u256() { let bytes = BytesTrait::new(42, array); let (new_offset, value) = bytes.read_u256(4); - assert(new_offset == 36, 'read_u256_1_offset'); - assert(value.high == 0x05060708091011121314151601020304, 'read_u256_1_value_high'); - assert(value.low == 0x05060708091011121314151601020304, 'read_u256_1_value_low'); + assert_eq!(new_offset, 36, "read_u256_1_offset"); + assert_eq!(value.high, 0x05060708091011121314151601020304, "read_u256_1_value_high"); + assert_eq!(value.low, 0x05060708091011121314151601020304, "read_u256_1_value_low"); } #[test] #[available_gas(20000000)] fn test_bytes_read_u256_array() { - let mut array = array![ + let array = array![ 0x01020304050607080910111213141516, 0x16151413121110090807060504030201, 0x16151413121110090807060504030201, @@ -366,68 +366,70 @@ fn test_bytes_read_u256_array() { let bytes = BytesTrait::new(88, array); let (new_offset, new_array) = bytes.read_u256_array(7, 2); - assert(new_offset == 71, 'read_u256_array_offset'); + assert_eq!(new_offset, 71, "read_u256_array_offset"); let result: u256 = *new_array[0]; - assert(result.high == 0x08091011121314151616151413121110, 'read_256_array_value_1_high'); - assert(result.low == 0x09080706050403020116151413121110, 'read_256_array_value_1_low'); + assert_eq!(result.high, 0x08091011121314151616151413121110, "read_256_array_value_1_high"); + assert_eq!(result.low, 0x09080706050403020116151413121110, "read_256_array_value_1_low"); let result: u256 = *new_array[1]; - assert(result.high == 0x09080706050403020101020304050607, 'read_256_array_value_2_high'); - assert(result.low == 0x08091011121314151601020304050607, 'read_256_array_value_2_low'); + assert_eq!(result.high, 0x09080706050403020101020304050607, "read_256_array_value_2_high"); + assert_eq!(result.low, 0x08091011121314151601020304050607, "read_256_array_value_2_low"); } #[test] #[available_gas(20000000)] fn test_bytes_read_address() { - let mut array = array![]; - array.append(0x01020304050607080910111213140154); - array.append(0x01855d7796176b05d160196ff92381eb); - array.append(0x7910f5446c2e0e04e13db2194a4f0000); + let array = array![ + 0x01020304050607080910111213140154, + 0x01855d7796176b05d160196ff92381eb, + 0x7910f5446c2e0e04e13db2194a4f0000, + ]; let bytes = BytesTrait::new(46, array); let address = 0x015401855d7796176b05d160196ff92381eb7910f5446c2e0e04e13db2194a4f; let (new_offset, value) = bytes.read_address(14); - assert(new_offset == 46, 'read_address_offset'); - assert(value.into() == address, 'read_address_value'); + assert_eq!(new_offset, 46, "read_address_offset"); + assert_eq!(value.into(), address, "read_address_value"); } #[test] #[available_gas(20000000)] fn test_bytes_read_bytes() { - let mut array = array![]; - array.append(0x01020304050607080910111213140154); - array.append(0x01855d7796176b05d160196ff92381eb); - array.append(0x7910f5446c2e0e04e13db2194a4f0000); + let array = array![ + 0x01020304050607080910111213140154, + 0x01855d7796176b05d160196ff92381eb, + 0x7910f5446c2e0e04e13db2194a4f0000, + ]; let bytes = BytesTrait::new(46, array); let (new_offset, sub_bytes) = bytes.read_bytes(4, 37); let sub_bytes_data = @sub_bytes.data; - assert(new_offset == 41, 'read_bytes_offset'); - assert(sub_bytes.size() == 37, 'read_bytes_size'); - assert(*sub_bytes_data[0] == 0x05060708091011121314015401855d77, 'read_bytes_value_1'); - assert(*sub_bytes_data[1] == 0x96176b05d160196ff92381eb7910f544, 'read_bytes_value_2'); - assert(*sub_bytes_data[2] == 0x6c2e0e04e10000000000000000000000, 'read_bytes_value_3'); + assert_eq!(new_offset, 41, "read_bytes_offset"); + assert_eq!(sub_bytes.size(), 37, "read_bytes_size"); + assert_eq!(*sub_bytes_data[0], 0x05060708091011121314015401855d77, "read_bytes_value_1"); + assert_eq!(*sub_bytes_data[1], 0x96176b05d160196ff92381eb7910f544, "read_bytes_value_2"); + assert_eq!(*sub_bytes_data[2], 0x6c2e0e04e10000000000000000000000, "read_bytes_value_3"); let (new_offset, sub_bytes) = bytes.read_bytes(0, 14); let sub_bytes_data = @sub_bytes.data; - assert(new_offset == 14, 'read_bytes_offset'); - assert(sub_bytes.size() == 14, 'read_bytes_size'); - assert(*sub_bytes_data[0] == 0x01020304050607080910111213140000, 'read_bytes_value_4'); + assert_eq!(new_offset, 14, "read_bytes_offset"); + assert_eq!(sub_bytes.size(), 14, "read_bytes_size"); + assert_eq!(*sub_bytes_data[0], 0x01020304050607080910111213140000, "read_bytes_value_4"); // read first byte let (new_offset, sub_bytes) = bytes.read_bytes(0, 1); let sub_bytes_data = @sub_bytes.data; - assert(new_offset == 1, 'read_bytes_offset'); - assert(sub_bytes.size() == 1, 'read_bytes_size'); - assert(*sub_bytes_data[0] == 0x01000000000000000000000000000000, 'read_bytes_value_5'); + assert_eq!(new_offset, 1, "read_bytes_offset"); + assert_eq!(sub_bytes.size(), 1, "read_bytes_size"); + assert_eq!(*sub_bytes_data[0], 0x01000000000000000000000000000000, "read_bytes_value_5"); // read last byte let (new_offset, sub_bytes) = bytes.read_bytes(45, 1); let sub_bytes_data = @sub_bytes.data; - assert(new_offset == 46, 'read_bytes_offset'); - assert(sub_bytes.size() == 1, 'read_bytes_size'); - assert(*sub_bytes_data[0] == 0x4f000000000000000000000000000000, 'read_bytes_value_6'); + assert_eq!(new_offset, 46, "read_bytes_offset"); + assert_eq!(sub_bytes.size(), 1, "read_bytes_size"); + assert_eq!(*sub_bytes_data[0], 0x4f000000000000000000000000000000, "read_bytes_value_6"); } #[test] @@ -438,78 +440,78 @@ fn test_bytes_append() { // append_u128_packed bytes.append_u128_packed(0x101112131415161718, 9); let Bytes{size, mut data } = bytes; - assert(size == 9, 'append_u128_packed_1_size'); - assert(*data[0] == 0x10111213141516171800000000000000, 'append_u128_packed_1_value_1'); + assert_eq!(size, 9, "append_u128_packed_1_size"); + assert_eq!(*data[0], 0x10111213141516171800000000000000, "append_u128_packed_1_value_1"); bytes = Bytes { size: size, data: data }; bytes.append_u128_packed(0x101112131415161718, 9); let Bytes{size, mut data } = bytes; - assert(size == 18, 'append_u128_packed_2_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'append_u128_packed_2_value_1'); - assert(*data[1] == 0x17180000000000000000000000000000, 'append_u128_packed_2_value_2'); + assert_eq!(size, 18, "append_u128_packed_2_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "append_u128_packed_2_value_1"); + assert_eq!(*data[1], 0x17180000000000000000000000000000, "append_u128_packed_2_value_2"); bytes = Bytes { size: size, data: data }; // append_u8 bytes.append_u8(0x01); let Bytes{size, mut data } = bytes; - assert(size == 19, 'append_u8_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'append_u8_value_1'); - assert(*data[1] == 0x17180100000000000000000000000000, 'append_u8_value_2'); + assert_eq!(size, 19, "append_u8_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "append_u8_value_1"); + assert_eq!(*data[1], 0x17180100000000000000000000000000, "append_u8_value_2"); bytes = Bytes { size: size, data: data }; // append_u16 bytes.append_u16(0x0102); let Bytes{size, mut data } = bytes; - assert(size == 21, 'append_u16_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'append_u16_value_1'); - assert(*data[1] == 0x17180101020000000000000000000000, 'append_u16_value_2'); + assert_eq!(size, 21, "append_u16_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "append_u16_value_1"); + assert_eq!(*data[1], 0x17180101020000000000000000000000, "append_u16_value_2"); bytes = Bytes { size: size, data: data }; // append_u32 bytes.append_u32(0x01020304); let Bytes{size, mut data } = bytes; - assert(size == 25, 'append_u32_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'append_u32_value_1'); - assert(*data[1] == 0x17180101020102030400000000000000, 'append_u32_value_2'); + assert_eq!(size, 25, "append_u32_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "append_u32_value_1"); + assert_eq!(*data[1], 0x17180101020102030400000000000000, "append_u32_value_2"); bytes = Bytes { size: size, data: data }; // append_usize bytes.append_usize(0x01); let Bytes{size, mut data } = bytes; - assert(size == 29, 'append_usize_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'append_usize_value_1'); - assert(*data[1] == 0x17180101020102030400000001000000, 'append_usize_value_2'); + assert_eq!(size, 29, "append_usize_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "append_usize_value_1"); + assert_eq!(*data[1], 0x17180101020102030400000001000000, "append_usize_value_2"); bytes = Bytes { size: size, data: data }; // append_u64 bytes.append_u64(0x030405060708); let Bytes{size, mut data } = bytes; - assert(size == 37, 'append_u64_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'append_u64_value_1'); - assert(*data[1] == 0x17180101020102030400000001000003, 'append_u64_value_2'); - assert(*data[2] == 0x04050607080000000000000000000000, 'append_u64_value_3'); + assert_eq!(size, 37, "append_u64_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "append_u64_value_1"); + assert_eq!(*data[1], 0x17180101020102030400000001000003, "append_u64_value_2"); + assert_eq!(*data[2], 0x04050607080000000000000000000000, "append_u64_value_3"); bytes = Bytes { size: size, data: data }; // append_u128 bytes.append_u128(0x101112131415161718); let Bytes{size, mut data } = bytes; - assert(size == 53, 'append_u128_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'append_u128_value_1'); - assert(*data[1] == 0x17180101020102030400000001000003, 'append_u128_value_2'); - assert(*data[2] == 0x04050607080000000000000010111213, 'append_u128_value_3'); - assert(*data[3] == 0x14151617180000000000000000000000, 'append_u128_value_4'); + assert_eq!(size, 53, "append_u128_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "append_u128_value_1"); + assert_eq!(*data[1], 0x17180101020102030400000001000003, "append_u128_value_2"); + assert_eq!(*data[2], 0x04050607080000000000000010111213, "append_u128_value_3"); + assert_eq!(*data[3], 0x14151617180000000000000000000000, "append_u128_value_4"); bytes = Bytes { size: size, data: data }; // append_u256 bytes.append_u256(u256 { low: 0x01020304050607, high: 0x010203040506070809 }); let Bytes{size, mut data } = bytes; - assert(size == 85, 'append_u256_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'append_u256_value_1'); - assert(*data[1] == 0x17180101020102030400000001000003, 'append_u256_value_2'); - assert(*data[2] == 0x04050607080000000000000010111213, 'append_u256_value_3'); - assert(*data[3] == 0x14151617180000000000000001020304, 'append_u256_value_4'); - assert(*data[4] == 0x05060708090000000000000000000102, 'append_u256_value_5'); - assert(*data[5] == 0x03040506070000000000000000000000, 'append_u256_value_6'); + assert_eq!(size, 85, "append_u256_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "append_u256_value_1"); + assert_eq!(*data[1], 0x17180101020102030400000001000003, "append_u256_value_2"); + assert_eq!(*data[2], 0x04050607080000000000000010111213, "append_u256_value_3"); + assert_eq!(*data[3], 0x14151617180000000000000001020304, "append_u256_value_4"); + assert_eq!(*data[4], 0x05060708090000000000000000000102, "append_u256_value_5"); + assert_eq!(*data[5], 0x03040506070000000000000000000000, "append_u256_value_6"); bytes = Bytes { size: size, data: data }; // append_address @@ -518,15 +520,15 @@ fn test_bytes_append() { .unwrap(); bytes.append_address(address); let Bytes{size, mut data } = bytes; - assert(size == 117, 'append_address_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'append_address_value_1'); - assert(*data[1] == 0x17180101020102030400000001000003, 'append_address_value_2'); - assert(*data[2] == 0x04050607080000000000000010111213, 'append_address_value_3'); - assert(*data[3] == 0x14151617180000000000000001020304, 'append_address_value_4'); - assert(*data[4] == 0x05060708090000000000000000000102, 'append_address_value_5'); - assert(*data[5] == 0x0304050607015401855d7796176b05d1, 'append_address_value_6'); - assert(*data[6] == 0x60196ff92381eb7910f5446c2e0e04e1, 'append_address_value_7'); - assert(*data[7] == 0x3db2194a4f0000000000000000000000, 'append_address_value_8'); + assert_eq!(size, 117, "append_address_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "append_address_value_1"); + assert_eq!(*data[1], 0x17180101020102030400000001000003, "append_address_value_2"); + assert_eq!(*data[2], 0x04050607080000000000000010111213, "append_address_value_3"); + assert_eq!(*data[3], 0x14151617180000000000000001020304, "append_address_value_4"); + assert_eq!(*data[4], 0x05060708090000000000000000000102, "append_address_value_5"); + assert_eq!(*data[5], 0x0304050607015401855d7796176b05d1, "append_address_value_6"); + assert_eq!(*data[6], 0x60196ff92381eb7910f5446c2e0e04e1, "append_address_value_7"); + assert_eq!(*data[7], 0x3db2194a4f0000000000000000000000, "append_address_value_8"); } #[test] @@ -544,7 +546,7 @@ fn test_bytes_concat() { ]; let mut bytes = BytesTrait::new(117, array); - let mut array: Array = array![ + let array: Array = array![ 0x01020304050607080910111213140154, 0x01855d7796176b05d160196ff92381eb, 0x7910f5446c2e0e04e13db2194a4f0000 @@ -553,18 +555,18 @@ fn test_bytes_concat() { bytes.concat(@other); let Bytes{size, mut data } = bytes; - assert(size == 163, 'concat_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'concat_value_1'); - assert(*data[1] == 0x17180101020102030400000001000003, 'concat_value_2'); - assert(*data[2] == 0x04050607080000000000000010111213, 'concat_value_3'); - assert(*data[3] == 0x14151617180000000000000001020304, 'concat_value_4'); - assert(*data[4] == 0x05060708090000000000000000000102, 'concat_value_5'); - assert(*data[5] == 0x0304050607015401855d7796176b05d1, 'concat_value_6'); - assert(*data[6] == 0x60196ff92381eb7910f5446c2e0e04e1, 'concat_value_7'); - assert(*data[7] == 0x3db2194a4f0102030405060708091011, 'concat_value_8'); - assert(*data[8] == 0x121314015401855d7796176b05d16019, 'concat_value_9'); - assert(*data[9] == 0x6ff92381eb7910f5446c2e0e04e13db2, 'concat_value_10'); - assert(*data[10] == 0x194a4f00000000000000000000000000, 'concat_value_11'); + assert_eq!(size, 163, "concat_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "concat_value_1"); + assert_eq!(*data[1], 0x17180101020102030400000001000003, "concat_value_2"); + assert_eq!(*data[2], 0x04050607080000000000000010111213, "concat_value_3"); + assert_eq!(*data[3], 0x14151617180000000000000001020304, "concat_value_4"); + assert_eq!(*data[4], 0x05060708090000000000000000000102, "concat_value_5"); + assert_eq!(*data[5], 0x0304050607015401855d7796176b05d1, "concat_value_6"); + assert_eq!(*data[6], 0x60196ff92381eb7910f5446c2e0e04e1, "concat_value_7"); + assert_eq!(*data[7], 0x3db2194a4f0102030405060708091011, "concat_value_8"); + assert_eq!(*data[8], 0x121314015401855d7796176b05d16019, "concat_value_9"); + assert_eq!(*data[9], 0x6ff92381eb7910f5446c2e0e04e13db2, "concat_value_10"); + assert_eq!(*data[10], 0x194a4f00000000000000000000000000, "concat_value_11"); bytes = Bytes { size: size, data: data }; // empty bytes concat @@ -572,35 +574,35 @@ fn test_bytes_concat() { empty_bytes.concat(@bytes); let Bytes{size, data } = empty_bytes; - assert(size == 163, 'concat_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'concat_value_1'); - assert(*data[1] == 0x17180101020102030400000001000003, 'concat_value_2'); - assert(*data[2] == 0x04050607080000000000000010111213, 'concat_value_3'); - assert(*data[3] == 0x14151617180000000000000001020304, 'concat_value_4'); - assert(*data[4] == 0x05060708090000000000000000000102, 'concat_value_5'); - assert(*data[5] == 0x0304050607015401855d7796176b05d1, 'concat_value_6'); - assert(*data[6] == 0x60196ff92381eb7910f5446c2e0e04e1, 'concat_value_7'); - assert(*data[7] == 0x3db2194a4f0102030405060708091011, 'concat_value_8'); - assert(*data[8] == 0x121314015401855d7796176b05d16019, 'concat_value_9'); - assert(*data[9] == 0x6ff92381eb7910f5446c2e0e04e13db2, 'concat_value_10'); - assert(*data[10] == 0x194a4f00000000000000000000000000, 'concat_value_11'); + assert_eq!(size, 163, "concat_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "concat_value_1"); + assert_eq!(*data[1], 0x17180101020102030400000001000003, "concat_value_2"); + assert_eq!(*data[2], 0x04050607080000000000000010111213, "concat_value_3"); + assert_eq!(*data[3], 0x14151617180000000000000001020304, "concat_value_4"); + assert_eq!(*data[4], 0x05060708090000000000000000000102, "concat_value_5"); + assert_eq!(*data[5], 0x0304050607015401855d7796176b05d1, "concat_value_6"); + assert_eq!(*data[6], 0x60196ff92381eb7910f5446c2e0e04e1, "concat_value_7"); + assert_eq!(*data[7], 0x3db2194a4f0102030405060708091011, "concat_value_8"); + assert_eq!(*data[8], 0x121314015401855d7796176b05d16019, "concat_value_9"); + assert_eq!(*data[9], 0x6ff92381eb7910f5446c2e0e04e13db2, "concat_value_10"); + assert_eq!(*data[10], 0x194a4f00000000000000000000000000, "concat_value_11"); // concat empty_bytes let empty_bytes = BytesTrait::new_empty(); bytes.concat(@empty_bytes); - assert(size == 163, 'concat_size'); - assert(*data[0] == 0x10111213141516171810111213141516, 'concat_value_1'); - assert(*data[1] == 0x17180101020102030400000001000003, 'concat_value_2'); - assert(*data[2] == 0x04050607080000000000000010111213, 'concat_value_3'); - assert(*data[3] == 0x14151617180000000000000001020304, 'concat_value_4'); - assert(*data[4] == 0x05060708090000000000000000000102, 'concat_value_5'); - assert(*data[5] == 0x0304050607015401855d7796176b05d1, 'concat_value_6'); - assert(*data[6] == 0x60196ff92381eb7910f5446c2e0e04e1, 'concat_value_7'); - assert(*data[7] == 0x3db2194a4f0102030405060708091011, 'concat_value_8'); - assert(*data[8] == 0x121314015401855d7796176b05d16019, 'concat_value_9'); - assert(*data[9] == 0x6ff92381eb7910f5446c2e0e04e13db2, 'concat_value_10'); - assert(*data[10] == 0x194a4f00000000000000000000000000, 'concat_value_11'); + assert_eq!(size, 163, "concat_size"); + assert_eq!(*data[0], 0x10111213141516171810111213141516, "concat_value_1"); + assert_eq!(*data[1], 0x17180101020102030400000001000003, "concat_value_2"); + assert_eq!(*data[2], 0x04050607080000000000000010111213, "concat_value_3"); + assert_eq!(*data[3], 0x14151617180000000000000001020304, "concat_value_4"); + assert_eq!(*data[4], 0x05060708090000000000000000000102, "concat_value_5"); + assert_eq!(*data[5], 0x0304050607015401855d7796176b05d1, "concat_value_6"); + assert_eq!(*data[6], 0x60196ff92381eb7910f5446c2e0e04e1, "concat_value_7"); + assert_eq!(*data[7], 0x3db2194a4f0102030405060708091011, "concat_value_8"); + assert_eq!(*data[8], 0x121314015401855d7796176b05d16019, "concat_value_9"); + assert_eq!(*data[9], 0x6ff92381eb7910f5446c2e0e04e13db2, "concat_value_10"); + assert_eq!(*data[10], 0x194a4f00000000000000000000000000, "concat_value_11"); } #[test] @@ -616,7 +618,7 @@ fn test_bytes_keccak() { let bytes = BytesTrait::new_empty(); let hash: u256 = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; let res = bytes.keccak(); - assert(res == hash, 'bytes_keccak_0'); + assert_eq!(res, hash, "bytes_keccak_0"); // u256{low: 1, high: 0} let mut array = array![]; @@ -625,7 +627,7 @@ fn test_bytes_keccak() { let bytes: Bytes = BytesTrait::new(32, array); let res = bytes.keccak(); let hash: u256 = 0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6; - assert(res == hash, 'bytes_keccak_1'); + assert_eq!(res, hash, "bytes_keccak_1"); // test_bytes_append bytes let mut array = array![]; @@ -642,7 +644,7 @@ fn test_bytes_keccak() { let hash: u256 = 0xcb1bcb5098bb2f588b82ea341e3b1148b7d1eeea2552d624b30f4240b5b85995; let res = bytes.keccak(); - assert(res == hash, 'bytes_keccak_2'); + assert_eq!(res, hash, "bytes_keccak_2"); } #[test] @@ -652,32 +654,31 @@ fn test_bytes_sha256() { let bytes = BytesTrait::new_empty(); let hash: u256 = 0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855; let res = bytes.sha256(); - assert(res == hash, 'bytes_sha256_0'); + assert_eq!(res, hash, "bytes_sha256_0"); // u256{low: 1, high: 0} // 0x0000000000000000000000000000000000000000000000000000000000000001 - let mut array = array![]; - array.append(0); - array.append(1); + let array = array![0, 1]; let bytes: Bytes = BytesTrait::new(32, array); let res = bytes.sha256(); let hash: u256 = 0xec4916dd28fc4c10d78e287ca5d9cc51ee1ae73cbfde08c6b37324cbfaac8bc5; - assert(res == hash, 'bytes_sha256_1'); + assert_eq!(res, hash, "bytes_sha256_1"); // test_bytes_append bytes - let mut array = array![]; - array.append(0x10111213141516171810111213141516); - array.append(0x17180101020102030400000001000003); - array.append(0x04050607080000000000000010111213); - array.append(0x14151617180000000000000001020304); - array.append(0x05060708090000000000000000000102); - array.append(0x0304050607015401855d7796176b05d1); - array.append(0x60196ff92381eb7910f5446c2e0e04e1); - array.append(0x3db2194a4f0000000000000000000000); + let array = array![ + 0x10111213141516171810111213141516, + 0x17180101020102030400000001000003, + 0x04050607080000000000000010111213, + 0x14151617180000000000000001020304, + 0x05060708090000000000000000000102, + 0x0304050607015401855d7796176b05d1, + 0x60196ff92381eb7910f5446c2e0e04e1, + 0x3db2194a4f0000000000000000000000, + ]; let bytes: Bytes = BytesTrait::new(117, array); let hash: u256 = 0xc3ab2c0ce2c246454f265f531ab14f210215ce72b91c23338405c273dc14ce1d; let res = bytes.sha256(); - assert(res == hash, 'bytes_sha256_2'); + assert_eq!(res, hash, "bytes_sha256_2"); } diff --git a/src/bytes/src/utils.cairo b/src/bytes/src/utils.cairo index b61329f3..48c9d676 100644 --- a/src/bytes/src/utils.cairo +++ b/src/bytes/src/utils.cairo @@ -6,7 +6,7 @@ use keccak::{u128_to_u64, u128_split as u128_split_to_u64, cairo_keccak}; /// The values are interpreted as big-endian. /// https://github.com/starkware-libs/cairo/blob/main/corelib/src/keccak.cairo fn keccak_u128s_be(mut input: Span, n_bytes: usize) -> u256 { - let mut keccak_input: Array:: = array![]; + let mut keccak_input = array![]; let mut size = n_bytes; loop { match input.pop_front() { @@ -68,13 +68,10 @@ fn keccak_add_uint128_be(ref keccak_input: Array::, value: u128, value_size fn update_u256_array_at(arr: @Array, index: usize, value: u256) -> Array { assert(index < arr.len(), 'index out of range'); - let mut new_arr: Array = array![]; + let mut new_arr = array![]; let mut i = 0; - loop { - if i == arr.len() { - break; - } + while i != arr.len() { if i == index { new_arr.append(value); } else { @@ -90,27 +87,15 @@ fn update_u256_array_at(arr: @Array, index: usize, value: u256) -> Array) -> u256 { assert(arr.len() == 32, 'too large'); let mut i = 0; - let mut high: u128 = 0; - let mut low: u128 = 0; + let mut high = 0; + let mut low = 0; // process high - loop { - if i >= arr.len() { - break; - } - if i == 16 { - break; - } + while i < arr.len() && i != 16 { high = u128_join(high, (*arr[i]).into(), 1); i += 1; }; // process low - loop { - if i >= arr.len() { - break; - } - if i == 32 { - break; - } + while i < arr.len() && i != 32 { low = u128_join(low, (*arr[i]).into(), 1); i += 1; }; @@ -121,14 +106,8 @@ fn u8_array_to_u256(arr: Span) -> u256 { fn u64_array_slice(src: @Array, mut begin: usize, end: usize) -> Array { let mut slice = array![]; let len = begin + end; - loop { - if begin >= len { - break; - } - if begin >= src.len() { - break; - } + while begin < len && begin < src.len() { slice.append(*src[begin]); begin += 1; }; @@ -144,14 +123,7 @@ fn u64_array_slice(src: @Array, mut begin: usize, end: usize) -> Array fn u128_array_slice(src: @Array, mut begin: usize, end: usize) -> Array { let mut slice = array![]; let len = begin + end; - loop { - if begin >= len { - break; - } - if begin >= src.len() { - break; - } - + while begin < len && begin < src.len() { slice.append(*src[begin]); begin += 1; }; @@ -175,12 +147,10 @@ fn u128_split(value: u128, value_size: usize, left_size: usize) -> (u128, u128) assert(left_size <= value_size, 'size can not be gt value_size'); if left_size == 0 { - (0_u128, value) + (0, value) } else { - let (left, right) = DivRem::div_rem( - value, u128_fast_pow2((value_size - left_size) * 8).try_into().expect('Division by 0') - ); - (left, right) + let power = u128_fast_pow2((value_size - left_size) * 8); + DivRem::div_rem(value, power.try_into().expect('Division by 0')) } } diff --git a/src/data_structures/src/bit_array.cairo b/src/data_structures/src/bit_array.cairo index 57a863d3..e41d9363 100644 --- a/src/data_structures/src/bit_array.cairo +++ b/src/data_structures/src/bit_array.cairo @@ -279,12 +279,9 @@ impl BitArrayImpl of BitArrayTrait { match self.pop_front() { Option::Some(bit) => { if bit { - result = - Option::Some( - (one_shift_left_bytes_felt252(byte_offset) - * shift_bit(bit_offset).into()) - + result.unwrap() - ); + let shifted = one_shift_left_bytes_felt252(byte_offset); + let value = (shifted * shift_bit(bit_offset).into()) + result.unwrap(); + result = Option::Some(value); } }, Option::None => { @@ -340,7 +337,7 @@ impl BitArrayImpl of BitArrayTrait { limb0: limb0.try_into().unwrap(), limb1: limb1.try_into().unwrap(), limb2: limb2.try_into().unwrap(), - limb3: limb3 + limb3 } } else if length > 128 { let limb0 = self.read_word_le(128)?; @@ -348,17 +345,14 @@ impl BitArrayImpl of BitArrayTrait { let limb2 = 0; let limb3 = 0; u512 { - limb0: limb0.try_into().unwrap(), - limb1: limb1.try_into().unwrap(), - limb2: limb2, - limb3: limb3 + limb0: limb0.try_into().unwrap(), limb1: limb1.try_into().unwrap(), limb2, limb3 } } else { let limb0 = self.read_word_le(length)?; let limb1 = 0; let limb2 = 0; let limb3 = 0; - u512 { limb0: limb0.try_into().unwrap(), limb1: limb1, limb2: limb2, limb3: limb3 } + u512 { limb0: limb0.try_into().unwrap(), limb1, limb2, limb3 } } ) } @@ -460,8 +454,7 @@ impl BitArrayIndexView of IndexView { impl BitArraySerde of Serde { fn serialize(self: @BitArray, ref output: Array) { - let length = self.len(); - length.serialize(ref output); + self.len().serialize(ref output); let bytes31_arr = self.data.span(); serialize_array_helper(bytes31_arr, ref output); output.append(*self.current); @@ -475,9 +468,7 @@ impl BitArraySerde of Serde { ref serialized, array![], length_in_felts.into() )?; let current = *serialized.pop_front()?; - Option::Some( - BitArray { data: bytes31_arr, current: current, read_pos: 0, write_pos: length, } - ) + Option::Some(BitArray { data: bytes31_arr, current, read_pos: 0, write_pos: length }) } } diff --git a/src/data_structures/src/tests/array_ext_test.cairo b/src/data_structures/src/tests/array_ext_test.cairo index 1daf8242..a283eb65 100644 --- a/src/data_structures/src/tests/array_ext_test.cairo +++ b/src/data_structures/src/tests/array_ext_test.cairo @@ -5,82 +5,82 @@ use alexandria_data_structures::array_ext::{ArrayTraitExt, SpanTraitExt}; #[test] #[available_gas(2000000)] fn dedup_all_different() { - let mut destination = array![1, 2, 3, 4]; + let destination = array![1, 2, 3, 4]; let new_arr = destination.dedup(); - assert(*new_arr[0] == 1, 'Should be 1'); - assert(*new_arr[1] == 2, 'Should be 2'); - assert(*new_arr[2] == 3, 'Should be 3'); - assert(*new_arr[3] == 4, 'Should be 4'); - assert(new_arr.len() == 4, 'Len should be 4'); + assert_eq!(*new_arr[0], 1, "Should be 1"); + assert_eq!(*new_arr[1], 2, "Should be 2"); + assert_eq!(*new_arr[2], 3, "Should be 3"); + assert_eq!(*new_arr[3], 4, "Should be 4"); + assert_eq!(new_arr.len(), 4, "Len should be 4"); } #[test] #[available_gas(2000000)] fn dedup_one_match() { - let mut destination = array![1, 2, 2, 3, 4]; + let destination = array![1, 2, 2, 3, 4]; let new_arr = destination.dedup(); - assert(*new_arr[0] == 1, 'Should be 1'); - assert(*new_arr[1] == 2, 'Should be 2'); - assert(*new_arr[2] == 3, 'Should be 3'); - assert(*new_arr[3] == 4, 'Should be 4'); - assert(new_arr.len() == 4, 'Len should be 4'); + assert_eq!(*new_arr[0], 1, "Should be 1"); + assert_eq!(*new_arr[1], 2, "Should be 2"); + assert_eq!(*new_arr[2], 3, "Should be 3"); + assert_eq!(*new_arr[3], 4, "Should be 4"); + assert_eq!(new_arr.len(), 4, "Len should be 4"); } #[test] #[available_gas(2000000)] fn dedup_two_matches() { - let mut destination = array![1, 2, 2, 3, 4, 4]; + let destination = array![1, 2, 2, 3, 4, 4]; let new_arr = destination.dedup(); - assert(*new_arr[0] == 1, 'Should be 1'); - assert(*new_arr[1] == 2, 'Should be 2'); - assert(*new_arr[2] == 3, 'Should be 3'); - assert(*new_arr[3] == 4, 'Should be 4'); - assert(new_arr.len() == 4, 'Len should be 4'); + assert_eq!(*new_arr[0], 1, "Should be 1"); + assert_eq!(*new_arr[1], 2, "Should be 2"); + assert_eq!(*new_arr[2], 3, "Should be 3"); + assert_eq!(*new_arr[3], 4, "Should be 4"); + assert_eq!(new_arr.len(), 4, "Len should be 4"); } #[test] #[available_gas(2000000)] fn dedup_one_match_more() { - let mut destination = array![1, 2, 2, 2, 3, 4, 4]; + let destination = array![1, 2, 2, 2, 3, 4, 4]; let new_arr = destination.dedup(); - assert(*new_arr[0] == 1, 'Should be 1'); - assert(*new_arr[1] == 2, 'Should be 2'); - assert(*new_arr[2] == 3, 'Should be 3'); - assert(*new_arr[3] == 4, 'Should be 4'); - assert(new_arr.len() == 4, 'Len should be 4'); + assert_eq!(*new_arr[0], 1, "Should be 1"); + assert_eq!(*new_arr[1], 2, "Should be 2"); + assert_eq!(*new_arr[2], 3, "Should be 3"); + assert_eq!(*new_arr[3], 4, "Should be 4"); + assert_eq!(new_arr.len(), 4, "Len should be 4"); } #[test] #[available_gas(2000000)] fn dedup_all_same() { - let mut destination = array![2, 2, 2, 2]; + let destination = array![2, 2, 2, 2]; let new_arr = destination.dedup(); - assert(*new_arr[0] == 2, 'Should be 2'); - assert(new_arr.len() == 1, 'Len should be 1'); + assert_eq!(*new_arr[0], 2, "Should be 2"); + assert_eq!(new_arr.len(), 1, "Len should be 1"); } #[test] #[available_gas(2000000)] fn dedup_one_elem() { - let mut destination = array![2]; + let destination = array![2]; let new_arr = destination.dedup(); - assert(*new_arr[0] == 2, 'Should be 2'); - assert(new_arr.len() == 1, 'Len should be 1'); + assert_eq!(*new_arr[0], 2, "Should be 2"); + assert_eq!(new_arr.len(), 1, "Len should be 1"); } #[test] #[available_gas(2000000)] fn dedup_no_elem() { - let mut destination = ArrayTrait::::new(); + let destination: Array = array![]; let new_arr = destination.dedup(); - assert(new_arr.len() == 0, 'Len should be 0'); + assert_eq!(new_arr.len(), 0, "Len should be 0"); } #[test] @@ -89,13 +89,13 @@ fn dedup_multiple_duplicates_same() { let mut destination = array![1, 1, 3, 4, 3, 3, 3, 4, 2, 2]; let new_arr = destination.dedup(); - assert(new_arr.len() == 6, 'Len should be 6'); - assert(*new_arr[0] == 1, 'Should be 1'); - assert(*new_arr[1] == 3, 'Should be 3'); - assert(*new_arr[2] == 4, 'Should be 4'); - assert(*new_arr[3] == 3, 'Should be 3'); - assert(*new_arr[4] == 4, 'Should be 4'); - assert(*new_arr[5] == 2, 'Should be 2'); + assert_eq!(new_arr.len(), 6, "Len should be 6"); + assert_eq!(*new_arr[0], 1, "Should be 1"); + assert_eq!(*new_arr[1], 3, "Should be 3"); + assert_eq!(*new_arr[2], 4, "Should be 4"); + assert_eq!(*new_arr[3], 3, "Should be 3"); + assert_eq!(*new_arr[4], 4, "Should be 4"); + assert_eq!(*new_arr[5], 2, "Should be 2"); } // append_all @@ -106,10 +106,10 @@ fn append_all() { let mut destination = array![21]; let mut source = array![42, 84]; destination.append_all(ref source); - assert(destination.len() == 3, 'Len should be 3'); - assert(*destination[0] == 21, 'Should be 21'); - assert(*destination[1] == 42, 'Should be 42'); - assert(*destination[2] == 84, 'Should be 84'); + assert_eq!(destination.len(), 3, "Len should be 3"); + assert_eq!(*destination[0], 21, "Should be 21"); + assert_eq!(*destination[1], 42, "Should be 42"); + assert_eq!(*destination[2], 84, "Should be 84"); } #[test] @@ -118,10 +118,10 @@ fn append_all_different_type() { let mut destination = array![21_u128]; let mut source = array![42_u128, 84_u128]; destination.append_all(ref source); - assert(destination.len() == 3, 'Len should be 3'); - assert(*destination[0] == 21_u128, 'Should be 21_u128'); - assert(*destination[1] == 42_u128, 'Should be 42_u128'); - assert(*destination[2] == 84_u128, 'Should be 84_u128'); + assert_eq!(destination.len(), 3, "Len should be 3"); + assert_eq!(*destination[0], 21_u128, "Should be 21_u128"); + assert_eq!(*destination[1], 42_u128, "Should be 42_u128"); + assert_eq!(*destination[2], 84_u128, "Should be 84_u128"); } #[test] @@ -130,10 +130,10 @@ fn append_all_destination_empty() { let mut destination = array![]; let mut source = array![21, 42, 84]; destination.append_all(ref source); - assert(destination.len() == 3, 'Len should be 3'); - assert(*destination[0] == 21, 'Should be 21'); - assert(*destination[1] == 42, 'Should be 42'); - assert(*destination[2] == 84, 'Should be 84'); + assert_eq!(destination.len(), 3, "Len should be 3"); + assert_eq!(*destination[0], 21, "Should be 21"); + assert_eq!(*destination[1], 42, "Should be 42"); + assert_eq!(*destination[2], 84, "Should be 84"); } #[test] @@ -142,10 +142,10 @@ fn append_all_source_empty() { let mut destination = array![]; let mut source = array![21, 42, 84]; destination.append_all(ref source); - assert(destination.len() == 3, 'Len should be 3'); - assert(*destination[0] == 21, 'Should be 0'); - assert(*destination[1] == 42, 'Should be 1'); - assert(*destination[2] == 84, 'Should be 2'); + assert_eq!(destination.len(), 3, "Len should be 3"); + assert_eq!(*destination[0], 21, "Should be 0"); + assert_eq!(*destination[1], 42, "Should be 1"); + assert_eq!(*destination[2], 84, "Should be 2"); } #[test] @@ -154,8 +154,8 @@ fn append_all_both_empty() { let mut destination: Array = array![]; let mut source = array![]; destination.append_all(ref source); - assert(source.len() == 0, 'Len should be 0'); - assert(destination.len() == 0, 'Len should be 0'); + assert_eq!(source.len(), 0, "Len should be 0"); + assert_eq!(destination.len(), 0, "Len should be 0"); } // reverse @@ -165,10 +165,10 @@ fn append_all_both_empty() { fn reverse() { let mut arr = array![21, 42, 84]; let response = arr.reverse(); - assert(response.len() == 3, 'Len should be 3'); - assert(*response[0] == 84, 'Should be 84'); - assert(*response[1] == 42, 'Should be 42'); - assert(*response[2] == 21, 'Should be 21'); + assert_eq!(response.len(), 3, "Len should be 3"); + assert_eq!(*response[0], 84, "Should be 84"); + assert_eq!(*response[1], 42, "Should be 42"); + assert_eq!(*response[2], 21, "Should be 21"); } #[test] @@ -176,8 +176,8 @@ fn reverse() { fn reverse_size_1() { let mut arr = array![21]; let response = arr.reverse(); - assert(response.len() == 1, 'Len should be 1'); - assert(*response[0] == 21, 'Should be 21'); + assert_eq!(response.len(), 1, "Len should be 1"); + assert_eq!(*response[0], 21, "Should be 21"); } #[test] @@ -185,7 +185,7 @@ fn reverse_size_1() { fn reverse_empty() { let mut arr: Array = array![]; let response = arr.reverse(); - assert(response.len() == 0, 'Len should be 0'); + assert_eq!(response.len(), 0, "Len should be 0"); } #[test] @@ -193,10 +193,10 @@ fn reverse_empty() { fn reverse_different_type() { let mut arr = array![21_u128, 42_u128, 84_u128]; let response = arr.reverse(); - assert(response.len() == 3, 'Len should be 3'); - assert(*response[0] == 84_u128, 'Should be 84_u128'); - assert(*response[1] == 42_u128, 'Should be 42_u128'); - assert(*response[2] == 21_u128, 'Should be 21_u128'); + assert_eq!(response.len(), 3, "Len should be 3"); + assert_eq!(*response[0], 84_u128, "Should be 84_u128"); + assert_eq!(*response[1], 42_u128, "Should be 42_u128"); + assert_eq!(*response[2], 21_u128, "Should be 21_u128"); } #[test] @@ -204,10 +204,10 @@ fn reverse_different_type() { fn reverse_span() { let mut arr = array![21, 42, 84]; let response = arr.span().reverse(); - assert(response.len() == 3, 'Len should be 3'); - assert(*response[0] == 84, 'Should be 84'); - assert(*response[1] == 42, 'Should be 42'); - assert(*response[2] == 21, 'Should be 21'); + assert_eq!(response.len(), 3, "Len should be 3"); + assert_eq!(*response[0], 84, "Should be 84"); + assert_eq!(*response[1], 42, "Should be 42"); + assert_eq!(*response[2], 21, "Should be 21"); } #[test] @@ -215,8 +215,8 @@ fn reverse_span() { fn reverse_size_1_span() { let mut arr = array![21]; let response = arr.span().reverse(); - assert(response.len() == 1, 'Len should be 1'); - assert(*response[0] == 21, 'Should be 21'); + assert_eq!(response.len(), 1, "Len should be 1"); + assert_eq!(*response[0], 21, "Should be 21"); } #[test] @@ -224,7 +224,7 @@ fn reverse_size_1_span() { fn reverse_empty_span() { let mut arr: Array = array![]; let response = arr.span().reverse(); - assert(response.len() == 0, 'Len should be 0'); + assert_eq!(response.len(), 0, "Len should be 0"); } #[test] @@ -232,10 +232,10 @@ fn reverse_empty_span() { fn reverse_different_type_span() { let mut arr = array![21_u128, 42_u128, 84_u128]; let response = arr.span().reverse(); - assert(response.len() == 3, 'Len should be 3'); - assert(*response[0] == 84_u128, 'Should be 84_u128'); - assert(*response[1] == 42_u128, 'Should be 42_u128'); - assert(*response[2] == 21_u128, 'Should be 21_u128'); + assert_eq!(response.len(), 3, "Len should be 3"); + assert_eq!(*response[0], 84_u128, "Should be 84_u128"); + assert_eq!(*response[1], 42_u128, "Should be 42_u128"); + assert_eq!(*response[2], 21_u128, "Should be 21_u128"); } @@ -246,8 +246,8 @@ fn reverse_different_type_span() { fn pop_front_n() { let mut arr = get_felt252_array(); arr.pop_front_n(2); - assert(arr.len() == 1, 'Len should be 1'); - assert(arr.pop_front().unwrap() == 84, 'Should be 84'); + assert_eq!(arr.len(), 1, "Len should be 1"); + assert_eq!(arr.pop_front().unwrap(), 84, "Should be 84"); } #[test] @@ -255,17 +255,17 @@ fn pop_front_n() { fn pop_front_n_different_type() { let mut arr = get_u128_array(); arr.pop_front_n(2); - assert(arr.len() == 1, 'Len should be 1'); - assert(arr.pop_front().unwrap() == 84, 'Should be 84'); + assert_eq!(arr.len(), 1, "Len should be 1"); + assert_eq!(arr.pop_front().unwrap(), 84, "Should be 84"); } #[test] #[available_gas(2000000)] fn pop_front_n_empty_array() { let mut arr: Array = array![]; - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); arr.pop_front_n(2); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); } #[test] @@ -273,10 +273,10 @@ fn pop_front_n_empty_array() { fn pop_front_n_zero() { let mut arr = get_felt252_array(); arr.pop_front_n(0); - assert(arr.len() == 3, 'Len should be 1'); - assert(arr.pop_front().unwrap() == 21, 'Should be 21'); - assert(arr.pop_front().unwrap() == 42, 'Should be 42'); - assert(arr.pop_front().unwrap() == 84, 'Should be 84'); + assert_eq!(arr.len(), 3, "Len should be 1"); + assert_eq!(arr.pop_front().unwrap(), 21, "Should be 21"); + assert_eq!(arr.pop_front().unwrap(), 42, "Should be 42"); + assert_eq!(arr.pop_front().unwrap(), 84, "Should be 84"); } #[test] @@ -284,7 +284,7 @@ fn pop_front_n_zero() { fn pop_front_n_exact_len() { let mut arr = get_felt252_array(); arr.pop_front_n(3); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); } #[test] @@ -292,7 +292,7 @@ fn pop_front_n_exact_len() { fn pop_front_n_more_then_len() { let mut arr = get_felt252_array(); arr.pop_front_n(4); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); } #[test] @@ -300,8 +300,8 @@ fn pop_front_n_more_then_len() { fn pop_front_n_span() { let mut arr = get_felt252_array().span(); arr.pop_front_n(2); - assert(arr.len() == 1, 'Len should be 1'); - assert(*arr.pop_front().unwrap() == 84, 'Should be 84'); + assert_eq!(arr.len(), 1, "Len should be 1"); + assert_eq!(*arr.pop_front().unwrap(), 84, "Should be 84"); } #[test] @@ -309,17 +309,17 @@ fn pop_front_n_span() { fn pop_front_n_different_type_span() { let mut arr = get_u128_array().span(); arr.pop_front_n(2); - assert(arr.len() == 1, 'Len should be 1'); - assert(*arr.pop_front().unwrap() == 84, 'Should be 84'); + assert_eq!(arr.len(), 1, "Len should be 1"); + assert_eq!(*arr.pop_front().unwrap(), 84, "Should be 84"); } #[test] #[available_gas(2000000)] fn pop_front_n_empty_array_span() { let mut arr: Span = array![].span(); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); arr.pop_front_n(2); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); } #[test] @@ -327,10 +327,10 @@ fn pop_front_n_empty_array_span() { fn pop_front_n_zero_span() { let mut arr = get_felt252_array().span(); arr.pop_front_n(0); - assert(arr.len() == 3, 'Len should be 1'); - assert(*arr.pop_front().unwrap() == 21, 'Should be 21'); - assert(*arr.pop_front().unwrap() == 42, 'Should be 42'); - assert(*arr.pop_front().unwrap() == 84, 'Should be 84'); + assert_eq!(arr.len(), 3, "Len should be 1"); + assert_eq!(*arr.pop_front().unwrap(), 21, "Should be 21"); + assert_eq!(*arr.pop_front().unwrap(), 42, "Should be 42"); + assert_eq!(*arr.pop_front().unwrap(), 84, "Should be 84"); } #[test] @@ -338,7 +338,7 @@ fn pop_front_n_zero_span() { fn pop_front_n_exact_len_span() { let mut arr = get_felt252_array().span(); arr.pop_front_n(3); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); } #[test] @@ -346,7 +346,7 @@ fn pop_front_n_exact_len_span() { fn pop_front_n_more_then_len_span() { let mut arr = get_felt252_array().span(); arr.pop_front_n(4); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); } // pop back n @@ -355,8 +355,8 @@ fn pop_front_n_more_then_len_span() { fn pop_back_n_span() { let mut arr = get_felt252_array().span(); arr.pop_back_n(2); - assert(arr.len() == 1, 'Len should be 1'); - assert(*arr.pop_back().unwrap() == 21, 'Should be 21'); + assert_eq!(arr.len(), 1, "Len should be 1"); + assert_eq!(*arr.pop_back().unwrap(), 21, "Should be 21"); } #[test] @@ -364,17 +364,17 @@ fn pop_back_n_span() { fn pop_back_n_different_type_span() { let mut arr = get_u128_array().span(); arr.pop_back_n(2); - assert(arr.len() == 1, 'Len should be 1'); - assert(*arr.pop_back().unwrap() == 21, 'Should be 21'); + assert_eq!(arr.len(), 1, "Len should be 1"); + assert_eq!(*arr.pop_back().unwrap(), 21, "Should be 21"); } #[test] #[available_gas(2000000)] fn pop_back_n_empty_array_span() { let mut arr: Span = array![].span(); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); arr.pop_back_n(2); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); } #[test] @@ -382,10 +382,10 @@ fn pop_back_n_empty_array_span() { fn pop_back_n_zero_span() { let mut arr = get_felt252_array().span(); arr.pop_back_n(0); - assert(arr.len() == 3, 'Len should be 1'); - assert(*arr.pop_front().unwrap() == 21, 'Should be 21'); - assert(*arr.pop_front().unwrap() == 42, 'Should be 42'); - assert(*arr.pop_front().unwrap() == 84, 'Should be 84'); + assert_eq!(arr.len(), 3, "Len should be 1"); + assert_eq!(*arr.pop_front().unwrap(), 21, "Should be 21"); + assert_eq!(*arr.pop_front().unwrap(), 42, "Should be 42"); + assert_eq!(*arr.pop_front().unwrap(), 84, "Should be 84"); } #[test] @@ -393,7 +393,7 @@ fn pop_back_n_zero_span() { fn pop_back_n_exact_len_span() { let mut arr = get_felt252_array().span(); arr.pop_back_n(3); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); } #[test] @@ -401,7 +401,7 @@ fn pop_back_n_exact_len_span() { fn pop_back_n_more_then_len_span() { let mut arr = get_felt252_array().span(); arr.pop_back_n(4); - assert(arr.is_empty(), 'Should be empty'); + assert!(arr.is_empty(), "Should be empty"); } @@ -410,74 +410,74 @@ fn pop_back_n_more_then_len_span() { #[test] #[available_gas(2000000)] fn contains() { - let mut arr = get_felt252_array(); - assert(arr.contains(21), 'Should contain 21'); - assert(arr.contains(42), 'Should contain 42'); - assert(arr.contains(84), 'Should contain 84'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array(); + assert!(arr.contains(21), "Should contain 21"); + assert!(arr.contains(42), "Should contain 42"); + assert!(arr.contains(84), "Should contain 84"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn contains_different_type() { - let mut arr = get_u128_array(); - assert(arr.contains(21_u128), 'Should contain 21_u128'); - assert(arr.contains(42_u128), 'Should contain 42_u128'); - assert(arr.contains(84_u128), 'Should contain 84_u128'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array(); + assert!(arr.contains(21_u128), "Should contain 21_u128"); + assert!(arr.contains(42_u128), "Should contain 42_u128"); + assert!(arr.contains(84_u128), "Should contain 84_u128"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn contains_false() { - let mut arr = get_felt252_array(); - assert(!arr.contains(85), 'Should be false'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array(); + assert!(!arr.contains(85), "Should be false"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn contains_empty_array() { - let mut arr = array![]; - assert(!arr.contains(85), 'Should be false'); - assert(arr.len() == 0, 'arr should not be consummed'); + let arr = array![]; + assert!(!arr.contains(85), "Should be false"); + assert_eq!(arr.len(), 0, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn contains_span() { - let mut arr = get_felt252_array().span(); - assert(arr.contains(21), 'Should contain 21'); - assert(arr.contains(42), 'Should contain 42'); - assert(arr.contains(84), 'Should contain 84'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array().span(); + assert!(arr.contains(21), "Should contain 21"); + assert!(arr.contains(42), "Should contain 42"); + assert!(arr.contains(84), "Should contain 84"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn contains_different_type_span() { - let mut arr = get_u128_array().span(); - assert(arr.contains(21_u128), 'Should contain 21_u128'); - assert(arr.contains(42_u128), 'Should contain 42_u128'); - assert(arr.contains(84_u128), 'Should contain 84_u128'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array().span(); + assert!(arr.contains(21_u128), "Should contain 21_u128"); + assert!(arr.contains(42_u128), "Should contain 42_u128"); + assert!(arr.contains(84_u128), "Should contain 84_u128"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn contains_false_span() { - let mut arr = get_felt252_array().span(); - assert(!arr.contains(85), 'Should be false'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array().span(); + assert!(!arr.contains(85), "Should be false"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn contains_empty_array_span() { - let mut arr = (array![]).span(); - assert(!arr.contains(85), 'Should be false'); - assert(arr.len() == 0, 'arr should not be consummed'); + let arr = (array![]).span(); + assert!(!arr.contains(85), "Should be false"); + assert_eq!(arr.len(), 0, "arr should not be consummed"); } // index_of @@ -485,69 +485,69 @@ fn contains_empty_array_span() { #[test] #[available_gas(2000000)] fn index_of() { - let mut arr = get_felt252_array(); - assert(arr.index_of(21).unwrap() == 0, 'Index should be 0'); - assert(arr.index_of(42).unwrap() == 1, 'Index should be 1'); - assert(arr.index_of(84).unwrap() == 2, 'Index should be 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array(); + assert_eq!(arr.index_of(21).unwrap(), 0, "Index should be 0"); + assert_eq!(arr.index_of(42).unwrap(), 1, "Index should be 1"); + assert_eq!(arr.index_of(84).unwrap(), 2, "Index should be 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_different_type() { - let mut arr = get_u128_array(); - assert(arr.index_of(21_u128).unwrap() == 0, 'Index should be 0'); - assert(arr.index_of(42_u128).unwrap() == 1, 'Index should be 1'); - assert(arr.index_of(84_u128).unwrap() == 2, 'Index should be 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array(); + assert_eq!(arr.index_of(21_u128).unwrap(), 0, "Index should be 0"); + assert_eq!(arr.index_of(42_u128).unwrap(), 1, "Index should be 1"); + assert_eq!(arr.index_of(84_u128).unwrap(), 2, "Index should be 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_panic() { - let mut arr = get_felt252_array(); - assert(arr.index_of(12).is_none(), 'Should NOT contain 12'); + let arr = get_felt252_array(); + assert!(arr.index_of(12).is_none(), "Should NOT contain 12"); } #[test] #[available_gas(2000000)] fn index_of_empty_array() { - let mut arr = array![]; - assert(arr.index_of(21).is_none(), 'Should NOT contain 21'); + let arr = array![]; + assert!(arr.index_of(21).is_none(), "Should NOT contain 21"); } #[test] #[available_gas(2000000)] fn index_of_span() { - let mut arr = get_felt252_array().span(); - assert(arr.index_of(21).unwrap() == 0, 'Index should be 0'); - assert(arr.index_of(42).unwrap() == 1, 'Index should be 1'); - assert(arr.index_of(84).unwrap() == 2, 'Index should be 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array().span(); + assert_eq!(arr.index_of(21).unwrap(), 0, "Index should be 0"); + assert_eq!(arr.index_of(42).unwrap(), 1, "Index should be 1"); + assert_eq!(arr.index_of(84).unwrap(), 2, "Index should be 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_different_type_span() { - let mut arr = get_u128_array().span(); - assert(arr.index_of(21_u128).unwrap() == 0, 'Index should be 0'); - assert(arr.index_of(42_u128).unwrap() == 1, 'Index should be 1'); - assert(arr.index_of(84_u128).unwrap() == 2, 'Index should be 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array().span(); + assert_eq!(arr.index_of(21_u128).unwrap(), 0, "Index should be 0"); + assert_eq!(arr.index_of(42_u128).unwrap(), 1, "Index should be 1"); + assert_eq!(arr.index_of(84_u128).unwrap(), 2, "Index should be 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_panic_span() { - let mut arr = get_felt252_array().span(); - assert(arr.index_of(12).is_none(), 'Should NOT contain 12'); + let arr = get_felt252_array().span(); + assert!(arr.index_of(12).is_none(), "Should NOT contain 12"); } #[test] #[available_gas(2000000)] fn index_of_empty_array_span() { - let mut arr = (array![]).span(); - assert(arr.index_of(21).is_none(), 'Should NOT contain 21'); + let arr = array![].span(); + assert!(arr.index_of(21).is_none(), "Should NOT contain 21"); } // occurrences_of @@ -555,105 +555,105 @@ fn index_of_empty_array_span() { #[test] #[available_gas(2000000)] fn occurrences_of() { - let mut arr = get_felt252_array(); - assert(arr.occurrences_of(21) == 1, 'Should contain 21 exactly once'); - assert(arr.occurrences_of(42) == 1, 'Should contain 42 exactly once'); - assert(arr.occurrences_of(84) == 1, 'Should contain 84 exactly once'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array(); + assert_eq!(arr.occurrences_of(21), 1, "Should contain 21 exactly once"); + assert_eq!(arr.occurrences_of(42), 1, "Should contain 42 exactly once"); + assert_eq!(arr.occurrences_of(84), 1, "Should contain 84 exactly once"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_different_type() { - let mut arr = get_u128_array(); - assert(arr.occurrences_of(21_u128) == 1, 'Should contain 21 exactly once'); - assert(arr.occurrences_of(42_u128) == 1, 'Should contain 42 exactly once'); - assert(arr.occurrences_of(84_u128) == 1, 'Should contain 84 exactly once'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array(); + assert_eq!(arr.occurrences_of(21_u128), 1, "Should contain 21 exactly once"); + assert_eq!(arr.occurrences_of(42_u128), 1, "Should contain 42 exactly once"); + assert_eq!(arr.occurrences_of(84_u128), 1, "Should contain 84 exactly once"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_not_in_array() { - let mut arr = get_felt252_array(); - assert(arr.occurrences_of(12) == 0, 'Should contain exactly once'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array(); + assert_eq!(arr.occurrences_of(12), 0, "Should contain exactly once"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_empty_array() { - let mut arr = array![]; - assert(arr.occurrences_of(12) == 0, 'Should contain exactly 0'); - assert(arr.len() == 0, 'arr should not be consummed'); + let arr = array![]; + assert_eq!(arr.occurrences_of(12), 0, "Should contain exactly 0"); + assert_eq!(arr.len(), 0, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_double() { - let mut arr = array![21, 21, 84]; - assert(arr.occurrences_of(21) == 2, 'Should contain exactly 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![21, 21, 84]; + assert_eq!(arr.occurrences_of(21), 2, "Should contain exactly 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_filled() { - let mut arr = array![21, 21, 21]; - assert(arr.occurrences_of(21) == 3, 'Should contain exactly 3'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![21, 21, 21]; + assert_eq!(arr.occurrences_of(21), 3, "Should contain exactly 3"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_span() { - let mut arr = get_felt252_array().span(); - assert(arr.occurrences_of(21) == 1, 'Should contain 21 exactly once'); - assert(arr.occurrences_of(42) == 1, 'Should contain 42 exactly once'); - assert(arr.occurrences_of(84) == 1, 'Should contain 84 exactly once'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array().span(); + assert_eq!(arr.occurrences_of(21), 1, "Should contain 21 exactly once"); + assert_eq!(arr.occurrences_of(42), 1, "Should contain 42 exactly once"); + assert_eq!(arr.occurrences_of(84), 1, "Should contain 84 exactly once"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_different_type_span() { - let mut arr = get_u128_array().span(); - assert(arr.occurrences_of(21_u128) == 1, 'Should contain 21 exactly once'); - assert(arr.occurrences_of(42_u128) == 1, 'Should contain 42 exactly once'); - assert(arr.occurrences_of(84_u128) == 1, 'Should contain 84 exactly once'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array().span(); + assert_eq!(arr.occurrences_of(21_u128), 1, "Should contain 21 exactly once"); + assert_eq!(arr.occurrences_of(42_u128), 1, "Should contain 42 exactly once"); + assert_eq!(arr.occurrences_of(84_u128), 1, "Should contain 84 exactly once"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_not_in_array_span() { - let mut arr = get_felt252_array().span(); - assert(arr.occurrences_of(12) == 0, 'Should contain exactly once'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_felt252_array().span(); + assert_eq!(arr.occurrences_of(12), 0, "Should contain exactly once"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_empty_array_span() { - let mut arr = array![].span(); - assert(arr.occurrences_of(12) == 0, 'Should contain exactly 0'); - assert(arr.len() == 0, 'arr should not be consummed'); + let arr = array![].span(); + assert_eq!(arr.occurrences_of(12), 0, "Should contain exactly 0"); + assert_eq!(arr.len(), 0, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_double_span() { - let mut arr = array![21, 21, 84]; - assert(arr.span().occurrences_of(21) == 2, 'Should contain exactly 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![21, 21, 84]; + assert_eq!(arr.span().occurrences_of(21), 2, "Should contain exactly 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn occurrences_of_filled_span() { - let mut arr = array![21, 21, 21]; - assert(arr.span().occurrences_of(21) == 3, 'Should contain exactly 3'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![21, 21, 21]; + assert_eq!(arr.span().occurrences_of(21), 3, "Should contain exactly 3"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } // min @@ -661,9 +661,9 @@ fn occurrences_of_filled_span() { #[test] #[available_gas(2000000)] fn min() { - let mut arr = @get_u128_array(); - assert(arr.min().unwrap() == 21_u128, 'Min should be 21'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = @get_u128_array(); + assert_eq!(arr.min().unwrap(), 21_u128, "Min should be 21"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] @@ -671,8 +671,8 @@ fn min() { fn min_step_one() { let mut arr = get_u128_array(); arr.append(20_u128); - assert(arr.min().unwrap() == 20_u128, 'Min should be 20'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.min().unwrap(), 20_u128, "Min should be 20"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] @@ -680,39 +680,39 @@ fn min_step_one() { fn min_with_duplicate() { let mut arr = get_u128_array(); arr.append(21_u128); - assert(arr.min().unwrap() == 21_u128, 'Min should be 21'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.min().unwrap(), 21_u128, "Min should be 21"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn min_empty_array() { - let mut arr: @Array = @array![]; - assert(arr.index_of(12).is_none(), 'Should be None'); + let arr: @Array = @array![]; + assert!(arr.index_of(12).is_none(), "Should be None"); } #[test] #[available_gas(2000000)] fn min_one_item() { - let mut arr = array![21_u128]; - assert(arr.min().unwrap() == 21_u128, 'Min should be 21'); - assert(arr.len() == 1, 'arr should not be consummed'); + let arr = array![21_u128]; + assert_eq!(arr.min().unwrap(), 21_u128, "Min should be 21"); + assert_eq!(arr.len(), 1, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn min_last() { - let mut arr = array![84_u128, 42_u128, 21_u128]; - assert(arr.min().unwrap() == 21_u128, 'Min should be 21'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![84_u128, 42_u128, 21_u128]; + assert_eq!(arr.min().unwrap(), 21_u128, "Min should be 21"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn min_span() { - let mut arr = get_u128_array().span(); - assert(arr.min().unwrap() == 21_u128, 'Min should be 21'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array().span(); + assert_eq!(arr.min().unwrap(), 21_u128, "Min should be 21"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] @@ -720,8 +720,8 @@ fn min_span() { fn min_step_one_span() { let mut arr = get_u128_array(); arr.append(20_u128); - assert(arr.span().min().unwrap() == 20_u128, 'Min should be 20'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.span().min().unwrap(), 20_u128, "Min should be 20"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] @@ -729,31 +729,31 @@ fn min_step_one_span() { fn min_with_duplicate_span() { let mut arr = get_u128_array(); arr.append(21_u128); - assert(arr.span().min().unwrap() == 21_u128, 'Min should be 21'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.span().min().unwrap(), 21_u128, "Min should be 21"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn min_empty_array_span() { - let mut arr: Span = array![].span(); - assert(arr.index_of(12).is_none(), 'Should be None'); + let arr: Span = array![].span(); + assert!(arr.index_of(12).is_none(), "Should be None"); } #[test] #[available_gas(2000000)] fn min_one_item_span() { - let mut arr = array![21_u128]; - assert(arr.span().min().unwrap() == 21_u128, 'Min should be 21'); - assert(arr.len() == 1, 'arr should not be consummed'); + let arr = array![21_u128]; + assert_eq!(arr.span().min().unwrap(), 21_u128, "Min should be 21"); + assert_eq!(arr.len(), 1, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn min_last_span() { - let mut arr = array![84_u128, 42_u128, 21_u128]; - assert(arr.span().min().unwrap() == 21_u128, 'Min should be 21'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![84_u128, 42_u128, 21_u128]; + assert_eq!(arr.span().min().unwrap(), 21_u128, "Min should be 21"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } // index_of_min @@ -761,9 +761,9 @@ fn min_last_span() { #[test] #[available_gas(2000000)] fn index_of_min() { - let mut arr = get_u128_array(); - assert(arr.index_of_min().unwrap() == 0, 'index_of_min should be 0'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array(); + assert_eq!(arr.index_of_min().unwrap(), 0, "index_of_min should be 0"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] @@ -771,8 +771,8 @@ fn index_of_min() { fn index_of_min_step_one() { let mut arr = get_u128_array(); arr.append(20_u128); - assert(arr.index_of_min().unwrap() == 3, 'index_of_min should be 3'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.index_of_min().unwrap(), 3, "index_of_min should be 3"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] @@ -780,40 +780,40 @@ fn index_of_min_step_one() { fn index_of_min_with_duplicate() { let mut arr = get_u128_array(); arr.append(21_u128); - assert(arr.index_of_min().unwrap() == 0, 'index_of_min should be 0'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.index_of_min().unwrap(), 0, "index_of_min should be 0"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_min_empty_array() { - let mut arr: Array = array![]; - assert(arr.index_of_min().is_none(), 'Should be None'); + let arr: Array = array![]; + assert!(arr.index_of_min().is_none(), "Should be None"); } #[test] #[available_gas(2000000)] fn index_of_min_one_item() { - let mut arr = array![21_u128]; - assert(arr.index_of_min().unwrap() == 0, 'index_of_min should be 0'); - assert(arr.len() == 1, 'arr should not be consummed'); + let arr = array![21_u128]; + assert_eq!(arr.index_of_min().unwrap(), 0, "index_of_min should be 0"); + assert_eq!(arr.len(), 1, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_min_last() { - let mut arr = array![84_u128, 42_u128, 21_u128]; - assert(arr.index_of_min().unwrap() == 2, 'index_of_min should be 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![84_u128, 42_u128, 21_u128]; + assert_eq!(arr.index_of_min().unwrap(), 2, "index_of_min should be 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_min_span() { - let mut arr = get_u128_array(); - assert(arr.span().index_of_min().unwrap() == 0, 'index_of_min should be 0'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array(); + assert_eq!(arr.span().index_of_min().unwrap(), 0, "index_of_min should be 0"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] @@ -821,8 +821,8 @@ fn index_of_min_span() { fn index_of_min_step_one_span() { let mut arr = get_u128_array(); arr.append(20_u128); - assert(arr.span().index_of_min().unwrap() == 3, 'index_of_min should be 3'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.span().index_of_min().unwrap(), 3, "index_of_min should be 3"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] @@ -830,31 +830,31 @@ fn index_of_min_step_one_span() { fn index_of_min_with_duplicate_span() { let mut arr = get_u128_array(); arr.append(21_u128); - assert(arr.span().index_of_min().unwrap() == 0, 'index_of_min should be 0'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.span().index_of_min().unwrap(), 0, "index_of_min should be 0"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_min_empty_array_span() { - let mut arr: Array = array![]; - assert(arr.span().index_of_min().is_none(), 'Should be None'); + let arr: Array = array![]; + assert!(arr.span().index_of_min().is_none(), "Should be None"); } #[test] #[available_gas(2000000)] fn index_of_min_one_item_span() { - let mut arr = array![21_u128]; - assert(arr.span().index_of_min().unwrap() == 0, 'index_of_min should be 0'); - assert(arr.len() == 1, 'arr should not be consummed'); + let arr = array![21_u128]; + assert_eq!(arr.span().index_of_min().unwrap(), 0, "index_of_min should be 0"); + assert_eq!(arr.len(), 1, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_min_last_span() { - let mut arr = array![84_u128, 42_u128, 21_u128]; - assert(arr.span().index_of_min().unwrap() == 2, 'index_of_min should be 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![84_u128, 42_u128, 21_u128]; + assert_eq!(arr.span().index_of_min().unwrap(), 2, "index_of_min should be 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } // max @@ -862,9 +862,9 @@ fn index_of_min_last_span() { #[test] #[available_gas(2000000)] fn max() { - let mut arr = get_u128_array(); - assert(arr.max().unwrap() == 84_u128, 'Max should be 84'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array(); + assert_eq!(arr.max().unwrap(), 84_u128, "Max should be 84"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] @@ -872,8 +872,8 @@ fn max() { fn max_step_one() { let mut arr = get_u128_array(); arr.append(85_u128); - assert(arr.max().unwrap() == 85_u128, 'Max should be 85'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.max().unwrap(), 85_u128, "Max should be 85"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] @@ -881,39 +881,39 @@ fn max_step_one() { fn max_with_duplicate() { let mut arr = get_u128_array(); arr.append(84_u128); - assert(arr.max().unwrap() == 84_u128, 'Max should be 84'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.max().unwrap(), 84_u128, "Max should be 84"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn max_empty_array() { - let mut arr: @Array = @array![]; - assert(arr.index_of(12).is_none(), 'Should be None'); + let arr: @Array = @array![]; + assert!(arr.index_of(12).is_none(), "Should be None"); } #[test] #[available_gas(2000000)] fn max_one_item() { - let mut arr = array![21_u128]; - assert(arr.max().unwrap() == 21_u128, 'Max should be 21'); - assert(arr.len() == 1, 'arr should not be consummed'); + let arr = array![21_u128]; + assert_eq!(arr.max().unwrap(), 21_u128, "Max should be 21"); + assert_eq!(arr.len(), 1, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn max_first() { - let mut arr = array![84_u128, 42_u128, 21_u128]; - assert(arr.max().unwrap() == 84_u128, 'Max should be 84'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![84_u128, 42_u128, 21_u128]; + assert_eq!(arr.max().unwrap(), 84_u128, "Max should be 84"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn max_span() { - let mut arr = get_u128_array(); - assert(arr.max().unwrap() == 84_u128, 'Max should be 84'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array(); + assert_eq!(arr.max().unwrap(), 84_u128, "Max should be 84"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] @@ -921,8 +921,8 @@ fn max_span() { fn max_step_one_span() { let mut arr = get_u128_array(); arr.append(85_u128); - assert(arr.span().max().unwrap() == 85_u128, 'Max should be 85'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.span().max().unwrap(), 85_u128, "Max should be 85"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] @@ -930,31 +930,31 @@ fn max_step_one_span() { fn max_with_duplicate_span() { let mut arr = get_u128_array(); arr.append(84_u128); - assert(arr.span().max().unwrap() == 84_u128, 'Max should be 84'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.span().max().unwrap(), 84_u128, "Max should be 84"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn max_empty_array_span() { - let mut arr: Span = array![].span(); - assert(arr.index_of(12).is_none(), 'Should be None'); + let arr: Span = array![].span(); + assert!(arr.index_of(12).is_none(), "Should be None"); } #[test] #[available_gas(2000000)] fn max_one_item_span() { - let mut arr = array![21_u128]; - assert(arr.span().max().unwrap() == 21_u128, 'Max should be 21'); - assert(arr.len() == 1, 'arr should not be consummed'); + let arr = array![21_u128]; + assert_eq!(arr.span().max().unwrap(), 21_u128, "Max should be 21"); + assert_eq!(arr.len(), 1, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn max_first_span() { - let mut arr = array![84_u128, 42_u128, 21_u128]; - assert(arr.span().max().unwrap() == 84_u128, 'Max should be 84'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![84_u128, 42_u128, 21_u128]; + assert_eq!(arr.span().max().unwrap(), 84_u128, "Max should be 84"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } // index_of_max @@ -962,9 +962,9 @@ fn max_first_span() { #[test] #[available_gas(2000000)] fn index_of_max() { - let mut arr = get_u128_array(); - assert(arr.index_of_max().unwrap() == 2, 'index_of_max should be 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array(); + assert_eq!(arr.index_of_max().unwrap(), 2, "index_of_max should be 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] @@ -972,8 +972,8 @@ fn index_of_max() { fn index_of_max_step_one() { let mut arr = get_u128_array(); arr.append(85_u128); - assert(arr.index_of_max().unwrap() == 3, 'index_of_max should be 3'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.index_of_max().unwrap(), 3, "index_of_max should be 3"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] @@ -981,40 +981,40 @@ fn index_of_max_step_one() { fn index_of_max_with_duplicate() { let mut arr = get_u128_array(); arr.append(84_u128); - assert(arr.index_of_max().unwrap() == 2, 'index_of_max should be 2'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.index_of_max().unwrap(), 2, "index_of_max should be 2"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_max_empty_array() { - let mut arr: Array = array![]; - assert(arr.index_of_max().is_none(), 'Should be None'); + let arr: Array = array![]; + assert!(arr.index_of_max().is_none(), "Should be None"); } #[test] #[available_gas(2000000)] fn index_of_max_one_item() { - let mut arr = array![21_u128]; - assert(arr.index_of_max().unwrap() == 0, 'index_of_max should be 0'); - assert(arr.len() == 1, 'arr should not be consummed'); + let arr = array![21_u128]; + assert_eq!(arr.index_of_max().unwrap(), 0, "index_of_max should be 0"); + assert_eq!(arr.len(), 1, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_max_last() { - let mut arr = array![84_u128, 42_u128, 21_u128]; - assert(arr.index_of_max().unwrap() == 0, 'index_of_max should be 0'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![84_u128, 42_u128, 21_u128]; + assert_eq!(arr.index_of_max().unwrap(), 0, "index_of_max should be 0"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_max_span() { - let mut arr = get_u128_array(); - assert(arr.span().index_of_max().unwrap() == 2, 'index_of_max should be 2'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = get_u128_array(); + assert_eq!(arr.span().index_of_max().unwrap(), 2, "index_of_max should be 2"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } #[test] @@ -1022,8 +1022,8 @@ fn index_of_max_span() { fn index_of_max_step_one_span() { let mut arr = get_u128_array(); arr.append(85_u128); - assert(arr.span().index_of_max().unwrap() == 3, 'index_of_max should be 3'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.span().index_of_max().unwrap(), 3, "index_of_max should be 3"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] @@ -1031,31 +1031,31 @@ fn index_of_max_step_one_span() { fn index_of_max_with_duplicate_span() { let mut arr = get_u128_array(); arr.append(84_u128); - assert(arr.span().index_of_max().unwrap() == 2, 'index_of_max should be 2'); - assert(arr.len() == 4, 'arr should not be consummed'); + assert_eq!(arr.span().index_of_max().unwrap(), 2, "index_of_max should be 2"); + assert_eq!(arr.len(), 4, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_max_empty_array_span() { - let mut arr: Array = array![]; - assert(arr.span().index_of_max().is_none(), 'Should be None'); + let arr: Array = array![]; + assert!(arr.span().index_of_max().is_none(), "Should be None"); } #[test] #[available_gas(2000000)] fn index_of_max_one_item_span() { - let mut arr = array![21_u128]; - assert(arr.span().index_of_max().unwrap() == 0, 'index_of_max should be 0'); - assert(arr.len() == 1, 'arr should not be consummed'); + let arr = array![21_u128]; + assert_eq!(arr.span().index_of_max().unwrap(), 0, "index_of_max should be 0"); + assert_eq!(arr.len(), 1, "arr should not be consummed"); } #[test] #[available_gas(2000000)] fn index_of_max_last_span() { - let mut arr = array![84_u128, 42_u128, 21_u128]; - assert(arr.span().index_of_max().unwrap() == 0, 'index_of_max should be 0'); - assert(arr.len() == 3, 'arr should not be consummed'); + let arr = array![84_u128, 42_u128, 21_u128]; + assert_eq!(arr.span().index_of_max().unwrap(), 0, "index_of_max should be 0"); + assert_eq!(arr.len(), 3, "arr should not be consummed"); } // unique @@ -1063,87 +1063,85 @@ fn index_of_max_last_span() { #[test] #[available_gas(2000000)] fn unique() { - let mut arr = array![32_u128, 256_u128, 128_u128, 256_u128, 1024_u128]; - let mut out_arr = arr.unique(); - assert(out_arr.len() == 4, 'Duplicates should be dropped'); - assert(*out_arr[0] == 32_u128, 'Should be 32'); - assert(*out_arr[1] == 256_u128, 'Should be 256'); - assert(*out_arr[2] == 128_u128, 'Should be 128'); - assert(*out_arr[3] == 1024_u128, 'Should be 1024'); + let arr = array![32_u128, 256_u128, 128_u128, 256_u128, 1024_u128]; + let out_arr = arr.unique(); + assert_eq!(out_arr.len(), 4, "Duplicates should be dropped"); + assert_eq!(*out_arr[0], 32_u128, "Should be 32"); + assert_eq!(*out_arr[1], 256_u128, "Should be 256"); + assert_eq!(*out_arr[2], 128_u128, "Should be 128"); + assert_eq!(*out_arr[3], 1024_u128, "Should be 1024"); } #[test] #[available_gas(2000000)] fn unique_all() { - let mut arr = array![84_u128, 84_u128, 84_u128]; - let mut out_arr = arr.unique(); - assert(out_arr.len() == 1, 'Duplicates should be dropped'); - assert(*out_arr[0] == 84_u128, 'Should be 128'); + let arr = array![84_u128, 84_u128, 84_u128]; + let out_arr = arr.unique(); + assert_eq!(out_arr.len(), 1, "Duplicates should be dropped"); + assert_eq!(*out_arr[0], 84_u128, "Should be 128"); } #[test] #[available_gas(2000000)] fn unique_none() { - let mut arr: Array = array![]; - let mut out_arr = arr.unique(); - assert(out_arr.len() == 0, 'out_arr should be empty'); + let arr: Array = array![]; + let out_arr = arr.unique(); + assert_eq!(out_arr.len(), 0, "out_arr should be empty"); } #[test] #[available_gas(2000000)] fn unique_at_start() { - let mut arr = array![16_u128, 16_u128, 16_u128, 128_u128, 64_u128, 32_u128]; - let mut out_arr = arr.unique(); - assert(out_arr.len() == 4, 'Duplicates should be dropped'); - assert(*out_arr[0] == 16_u128, 'Should be 16'); - assert(*out_arr[1] == 128_u128, 'Should be 128'); - assert(*out_arr[2] == 64_u128, 'Should be 64'); - assert(*out_arr[3] == 32_u128, 'Should be 32'); + let arr = array![16_u128, 16_u128, 16_u128, 128_u128, 64_u128, 32_u128]; + let out_arr = arr.unique(); + assert_eq!(out_arr.len(), 4, "Duplicates should be dropped"); + assert_eq!(*out_arr[0], 16_u128, "Should be 16"); + assert_eq!(*out_arr[1], 128_u128, "Should be 128"); + assert_eq!(*out_arr[2], 64_u128, "Should be 64"); + assert_eq!(*out_arr[3], 32_u128, "Should be 32"); } #[test] #[available_gas(2000000)] fn unique_at_middle() { - let mut arr = array![128_u128, 256_u128, 84_u128, 84_u128, 84_u128, 1_u128]; - let mut out_arr = arr.unique(); - assert(out_arr.len() == 4, 'Duplicates should be dropped'); - assert(*out_arr[0] == 128_u128, 'Should be 128'); - assert(*out_arr[1] == 256_u128, 'Should be 256'); - assert(*out_arr[2] == 84_u128, 'Should be 84'); - assert(*out_arr[3] == 1_u128, 'Should be 1'); + let arr = array![128_u128, 256_u128, 84_u128, 84_u128, 84_u128, 1_u128]; + let out_arr = arr.unique(); + assert_eq!(out_arr.len(), 4, "Duplicates should be dropped"); + assert_eq!(*out_arr[0], 128_u128, "Should be 128"); + assert_eq!(*out_arr[1], 256_u128, "Should be 256"); + assert_eq!(*out_arr[2], 84_u128, "Should be 84"); + assert_eq!(*out_arr[3], 1_u128, "Should be 1"); } #[test] #[available_gas(2000000)] fn unique_at_end() { - let mut arr = array![32_u128, 16_u128, 64_u128, 128_u128, 128_u128, 128_u128]; - let mut out_arr = arr.unique(); - assert(out_arr.len() == 4, 'Duplicates should be dropped'); - assert(*out_arr[0] == 32_u128, 'Should be 32'); - assert(*out_arr[1] == 16_u128, 'Should be 16'); - assert(*out_arr[2] == 64_u128, 'Should be 64'); - assert(*out_arr[3] == 128_u128, 'Should be 128'); + let arr = array![32_u128, 16_u128, 64_u128, 128_u128, 128_u128, 128_u128]; + let out_arr = arr.unique(); + assert_eq!(out_arr.len(), 4, "Duplicates should be dropped"); + assert_eq!(*out_arr[0], 32_u128, "Should be 32"); + assert_eq!(*out_arr[1], 16_u128, "Should be 16"); + assert_eq!(*out_arr[2], 64_u128, "Should be 64"); + assert_eq!(*out_arr[3], 128_u128, "Should be 128"); } #[test] #[available_gas(2000000)] fn unique_without_duplicates() { - let mut arr = array![42_u128, 84_u128, 21_u128]; - let mut out_arr = arr.unique(); - assert(out_arr.len() == 3, 'No values should drop'); - assert(*out_arr[0] == 42_u128, 'Should be 42'); - assert(*out_arr[1] == 84_u128, 'Should be 84'); - assert(*out_arr[2] == 21_u128, 'Should be 21'); + let arr = array![42_u128, 84_u128, 21_u128]; + let out_arr = arr.unique(); + assert_eq!(out_arr.len(), 3, "No values should drop"); + assert_eq!(*out_arr[0], 42_u128, "Should be 42"); + assert_eq!(*out_arr[1], 84_u128, "Should be 84"); + assert_eq!(*out_arr[2], 21_u128, "Should be 21"); } // Utility fn fn get_felt252_array() -> Array { - let mut arr = array![21, 42, 84]; - arr + array![21, 42, 84] } fn get_u128_array() -> Array { - let mut arr = array![21_u128, 42_u128, 84_u128]; - arr + array![21_u128, 42_u128, 84_u128] } diff --git a/src/data_structures/src/tests/bit_array_test.cairo b/src/data_structures/src/tests/bit_array_test.cairo index c96feac5..b6ddace2 100644 --- a/src/data_structures/src/tests/bit_array_test.cairo +++ b/src/data_structures/src/tests/bit_array_test.cairo @@ -20,7 +20,7 @@ fn test_append_bit() { .try_into() .unwrap(); let expected: Array = array![val, val,]; - assert(ba.data == expected, 'illegal array'); + assert!(ba.data == expected, "illegal array"); assert( ba.current == 0xa * one_shift_left_bytes_felt252(30) * shift_bit(4).into(), 'expected current 0xa' @@ -35,10 +35,10 @@ fn test_at() { loop { if index == 8 * 16 - 1 { // last value - assert(ba[index] == false, 'expected false'); + assert!(ba[index] == false, "expected false"); break; } - assert(ba.at(index).unwrap() == true, 'expected true'); + assert!(ba.at(index).unwrap() == true, "expected true"); index += 1; }; } @@ -47,15 +47,15 @@ fn test_at() { #[available_gas(2000000)] fn test_at_none() { let ba = sample_bit_array(); - assert(ba.at(8 * 16).is_none(), 'expected none'); + assert!(ba.at(8 * 16).is_none(), "expected none"); } #[test] #[available_gas(20000000)] fn test_index() { let ba = sample_bit_array(); - assert(ba[0] == true, 'expected true'); - assert(ba[8 * 16 - 1] == false, 'expected false'); + assert!(ba[0] == true, "expected true"); + assert!(ba[8 * 16 - 1] == false, "expected false"); } #[test] @@ -71,25 +71,25 @@ fn test_index_fail() { fn test_len() { let mut ba = sample_bit_array(); let expected = 8 * 16; - assert(ba.len() == expected, 'expected len 8 * 16'); + assert!(ba.len() == expected, "expected len 8 * 16"); ba.append_bit(true); - assert(ba.len() == expected + 1, 'expected len 8 * 16 + 1'); + assert!(ba.len() == expected + 1, "expected len 8 * 16 + 1"); let _ = ba.pop_front(); - assert(ba.len() == expected, 'expected len 8 * 16'); + assert!(ba.len() == expected, "expected len 8 * 16"); } #[test] #[available_gas(2000000)] fn test_pop_front() { let mut ba = sample_bit_array(); - assert(ba.pop_front() == Option::Some(true), 'expected (some) true'); + assert!(ba.pop_front() == Option::Some(true), "expected (some) true"); } #[test] #[available_gas(2000000)] fn test_pop_front_empty() { let mut ba: BitArray = Default::default(); - assert(ba.pop_front() == Option::None, 'expected none'); + assert!(ba.pop_front() == Option::None, "expected none"); } #[test] @@ -119,7 +119,7 @@ fn test_read_word_be_u256() { let low = 0x101112131415161718191a1b1c1d1e1f_u128; ba.write_word_be(low.into(), 128); let high = 0xfffffffffffffffffffffffffffffffe_u128; - assert(ba.read_word_be_u256(length: 256).unwrap() == u256 { low, high }, 'unexpected value'); + assert!(ba.read_word_be_u256(length: 256).unwrap() == u256 { low, high }, "unexpected value"); } #[test] @@ -129,7 +129,7 @@ fn test_read_word_le_u256() { let low = 0x7fffffffffffffffffffffffffffffff_u128; let high = 0x101112131415161718191a1b1c1d1e1f_u128; ba.write_word_le(high.into(), 128); - assert(ba.read_word_le_u256(length: 256).unwrap() == u256 { low, high }, 'unexpected value'); + assert!(ba.read_word_le_u256(length: 256).unwrap() == u256 { low, high }, "unexpected value"); } #[test] @@ -170,16 +170,16 @@ fn test_read_word_le_u512() { #[available_gas(20000000)] fn test_read_word_be_half() { let mut ba = sample_bit_array(); - assert(ba.read_word_be(64).unwrap() == 0xffffffffffffffff, 'unexpected result'); - assert(ba.read_word_be(64).unwrap() == 0xfffffffffffffffe, 'unexpected result'); + assert!(ba.read_word_be(64).unwrap() == 0xffffffffffffffff, "unexpected result"); + assert!(ba.read_word_be(64).unwrap() == 0xfffffffffffffffe, "unexpected result"); } #[test] #[available_gas(20000000)] fn test_read_word_le_half() { let mut ba = sample_bit_array(); - assert(ba.read_word_le(64).unwrap() == 0xffffffffffffffff, 'unexpected result'); - assert(ba.read_word_le(64).unwrap() == 0x7fffffffffffffff, 'unexpected result'); + assert!(ba.read_word_le(64).unwrap() == 0xffffffffffffffff, "unexpected result"); + assert!(ba.read_word_le(64).unwrap() == 0x7fffffffffffffff, "unexpected result"); } #[test] @@ -197,7 +197,9 @@ fn test_write_word_be() { fn test_write_word_be_half() { let mut ba: BitArray = Default::default(); ba.write_word_be(BoundedInt::::max().into() - 3, 64); - assert(ba.read_word_be(64).unwrap() == BoundedInt::::max().into() - 3, 'unexpected value'); + assert!( + ba.read_word_be(64).unwrap() == BoundedInt::::max().into() - 3, "unexpected value" + ); } #[test] @@ -215,7 +217,9 @@ fn test_write_word_le() { fn test_write_word_le_half() { let mut ba: BitArray = Default::default(); ba.write_word_le(BoundedInt::::max().into() - 5, 64); - assert(ba.read_word_le(64).unwrap() == BoundedInt::::max().into() - 5, 'unexpected value'); + assert!( + ba.read_word_le(64).unwrap() == BoundedInt::::max().into() - 5, "unexpected value" + ); } #[test] @@ -224,7 +228,7 @@ fn test_write_word_be_u256() { let mut ba: BitArray = Default::default(); let expected = u256 { low: BoundedInt::max() - 1, high: BoundedInt::max() - 2 }; ba.write_word_be_u256(expected, 256); - assert(ba.read_word_be_u256(256).unwrap() == expected, 'unexpected value'); + assert!(ba.read_word_be_u256(256).unwrap() == expected, "unexpected value"); } #[test] @@ -233,7 +237,7 @@ fn test_write_word_le_u256() { let mut ba: BitArray = Default::default(); let expected = u256 { low: BoundedInt::max() - 1, high: BoundedInt::max() - 2 }; ba.write_word_le_u256(expected, 256); - assert(ba.read_word_le_u256(256).unwrap() == expected, 'unexpected value'); + assert!(ba.read_word_le_u256(256).unwrap() == expected, "unexpected value"); } #[test] @@ -246,7 +250,7 @@ fn test_write_word_be_u512() { let limb3 = BoundedInt::::max() - 3; let expected = u512 { limb0, limb1, limb2, limb3 }; ba.write_word_be_u512(expected, 512); - assert(ba.read_word_be_u512(512).unwrap() == expected, 'unexpected value'); + assert!(ba.read_word_be_u512(512).unwrap() == expected, "unexpected value"); } #[test] @@ -259,7 +263,7 @@ fn test_write_word_le_u512() { let limb3 = BoundedInt::::max() - 3; let expected = u512 { limb0, limb1, limb2, limb3 }; ba.write_word_le_u512(expected, 512); - assert(ba.read_word_le_u512(512).unwrap() == expected, 'unexpected value'); + assert!(ba.read_word_le_u512(512).unwrap() == expected, "unexpected value"); } #[test] @@ -283,9 +287,9 @@ fn test_stress_test() { break; } let value = ba.read_word_be(248).unwrap(); - assert(value == index.into(), 'not equal'); + assert!(value == index.into(), "not equal"); let value = ba.read_word_le(248).unwrap(); - assert(value == index.into(), 'not equal'); + assert!(value == index.into(), "not equal"); index += 1; }; } @@ -298,11 +302,11 @@ fn test_serde_serialize() { ba.serialize(ref out); let length = out.pop_front().unwrap(); let length: usize = length.try_into().unwrap(); - assert(length == ba.len(), 'len not equal'); + assert!(length == ba.len(), "len not equal"); let data: felt252 = out.pop_front().unwrap(); let expected: felt252 = BoundedInt::::max().into() - 1; let expected = expected * one_shift_left_bytes_felt252(15); - assert(data == expected, 'unexpected data'); + assert!(data == expected, "unexpected data"); } #[test] @@ -320,13 +324,13 @@ fn test_serde_ser_deser() { ba.serialize(ref out); let mut span = out.span(); let mut deser = Serde::::deserialize(ref span).unwrap(); - assert(deser.len() == ba.len(), 'expected equal lengths'); - assert(deser.read_word_be(248).unwrap() == test, 'expected test'); - assert(deser.read_word_be(248).unwrap() == test + 1, 'expected test + 1'); - assert(deser.read_word_be(248).unwrap() == test + 2, 'expected test + 2'); - assert(deser.read_word_be(248).unwrap() == test + 3, 'expected test + 3'); - assert(deser.read_word_be(248).unwrap() == test + 4, 'expected test + 4'); - assert(deser.read_word_be(248).unwrap() == test + 5, 'expected test + 5'); + assert!(deser.len() == ba.len(), "expected equal lengths"); + assert!(deser.read_word_be(248).unwrap() == test, "expected test"); + assert!(deser.read_word_be(248).unwrap() == test + 1, "expected test + 1"); + assert!(deser.read_word_be(248).unwrap() == test + 2, "expected test + 2"); + assert!(deser.read_word_be(248).unwrap() == test + 3, "expected test + 3"); + assert!(deser.read_word_be(248).unwrap() == test + 4, "expected test + 4"); + assert!(deser.read_word_be(248).unwrap() == test + 5, "expected test + 5"); } // helpers diff --git a/src/data_structures/src/tests/byte_appender_test.cairo b/src/data_structures/src/tests/byte_appender_test.cairo index e4edec23..835ee6d5 100644 --- a/src/data_structures/src/tests/byte_appender_test.cairo +++ b/src/data_structures/src/tests/byte_appender_test.cairo @@ -13,7 +13,7 @@ fn test_append_u16() { ba.append_u16(0x0304_u16); ba.append_u16(0x0506_u16); ba.append_u16(0x0708_u16); - assert(ba == test_byte_array_8(), 'u16 differs'); + assert!(ba == test_byte_array_8(), "u16 differs"); } #[test] @@ -24,7 +24,7 @@ fn test_append_u16_arr() { ba.append_u16(0x0304_u16); ba.append_u16(0x0506_u16); ba.append_u16(0x0708_u16); - assert(ba == test_array_8(), 'u16 differs'); + assert!(ba == test_array_8(), "u16 differs"); } #[test] @@ -35,7 +35,7 @@ fn test_append_u16_le() { ba.append_u16_le(0x0403_u16); ba.append_u16_le(0x0605_u16); ba.append_u16_le(0x0807_u16); - assert(ba == test_byte_array_8(), 'u16 differs'); + assert!(ba == test_byte_array_8(), "u16 differs"); } #[test] @@ -46,7 +46,7 @@ fn test_append_u16_le_arr() { ba.append_u16_le(0x0403_u16); ba.append_u16_le(0x0605_u16); ba.append_u16_le(0x0807_u16); - assert(ba == test_array_8(), 'u16 differs'); + assert!(ba == test_array_8(), "u16 differs"); } #[test] @@ -55,7 +55,7 @@ fn test_append_u32() { let mut ba: ByteArray = Default::default(); ba.append_u32(0x01020304_u32); ba.append_u32(0x05060708_u32); - assert(ba == test_byte_array_8(), 'u32 differs'); + assert!(ba == test_byte_array_8(), "u32 differs"); } #[test] @@ -64,7 +64,7 @@ fn test_append_u32_arr() { let mut ba: Array = array![]; ba.append_u32(0x01020304_u32); ba.append_u32(0x05060708_u32); - assert(ba == test_array_8(), 'u32 differs'); + assert!(ba == test_array_8(), "u32 differs"); } #[test] @@ -73,7 +73,7 @@ fn test_append_u32_le() { let mut ba: ByteArray = Default::default(); ba.append_u32_le(0x04030201_u32); ba.append_u32_le(0x08070605_u32); - assert(ba == test_byte_array_8(), 'u32 differs'); + assert!(ba == test_byte_array_8(), "u32 differs"); } #[test] @@ -82,7 +82,7 @@ fn test_append_u32_le_arr() { let mut ba: Array = array![]; ba.append_u32_le(0x04030201_u32); ba.append_u32_le(0x08070605_u32); - assert(ba == test_array_8(), 'u32 differs'); + assert!(ba == test_array_8(), "u32 differs"); } #[test] @@ -91,7 +91,7 @@ fn test_append_u64() { let mut ba: ByteArray = Default::default(); ba.append_u64(0x0102030405060708_u64); ba.append_u64(0x090a0b0c0d0e0f10_u64); - assert(ba == test_byte_array_16(), 'u64 differs'); + assert!(ba == test_byte_array_16(), "u64 differs"); } #[test] @@ -100,7 +100,7 @@ fn test_append_u64_arr() { let mut ba: Array = array![]; ba.append_u64(0x0102030405060708_u64); ba.append_u64(0x090a0b0c0d0e0f10_u64); - assert(ba == test_array_16(), 'u64 differs'); + assert!(ba == test_array_16(), "u64 differs"); } #[test] @@ -109,7 +109,7 @@ fn test_append_u64_le() { let mut ba: ByteArray = Default::default(); ba.append_u64_le(0x0807060504030201_u64); ba.append_u64_le(0x100f0e0d0c0b0a09_u64); - assert(ba == test_byte_array_16(), 'u64 differs'); + assert!(ba == test_byte_array_16(), "u64 differs"); } #[test] @@ -118,7 +118,7 @@ fn test_append_u64_le_arr() { let mut ba: Array = array![]; ba.append_u64_le(0x0807060504030201_u64); ba.append_u64_le(0x100f0e0d0c0b0a09_u64); - assert(ba == test_array_16(), 'u64 differs'); + assert!(ba == test_array_16(), "u64 differs"); } #[test] @@ -127,7 +127,7 @@ fn test_append_u128() { let mut ba: ByteArray = Default::default(); ba.append_u128(0x0102030405060708090a0b0c0d0e0f10_u128); ba.append_u128(0x1112131415161718191a1b1c1d1e1f20_u128); - assert(ba == test_byte_array_32(), 'u128 differs'); + assert!(ba == test_byte_array_32(), "u128 differs"); } #[test] @@ -136,7 +136,7 @@ fn test_append_u128_arr() { let mut ba: Array = array![]; ba.append_u128(0x0102030405060708090a0b0c0d0e0f10_u128); ba.append_u128(0x1112131415161718191a1b1c1d1e1f20_u128); - assert(ba == test_array_32(), 'u128 differs'); + assert!(ba == test_array_32(), "u128 differs"); } #[test] @@ -145,7 +145,7 @@ fn test_append_u128_le() { let mut ba: ByteArray = Default::default(); ba.append_u128_le(0x100f0e0d0c0b0a090807060504030201_u128); ba.append_u128_le(0x201f1e1d1c1b1a191817161514131211_u128); - assert(ba == test_byte_array_32(), 'u128 differs'); + assert!(ba == test_byte_array_32(), "u128 differs"); } #[test] @@ -154,7 +154,7 @@ fn test_append_u128_le_arr() { let mut ba: Array = array![]; ba.append_u128_le(0x100f0e0d0c0b0a090807060504030201_u128); ba.append_u128_le(0x201f1e1d1c1b1a191817161514131211_u128); - assert(ba == test_array_32(), 'u128 differs'); + assert!(ba == test_array_32(), "u128 differs"); } #[test] @@ -165,7 +165,7 @@ fn test_append_u256() { high: 0x0102030405060708090a0b0c0d0e0f10_u128, low: 0x1112131415161718191a1b1c1d1e1f20_u128, }; ba.append_u256(word); - assert(ba == test_byte_array_32(), 'u256 differs'); + assert!(ba == test_byte_array_32(), "u256 differs"); } #[test] @@ -176,7 +176,7 @@ fn test_append_u256_arr() { high: 0x0102030405060708090a0b0c0d0e0f10_u128, low: 0x1112131415161718191a1b1c1d1e1f20_u128, }; ba.append_u256(word); - assert(ba == test_array_32(), 'u256 differs'); + assert!(ba == test_array_32(), "u256 differs"); } #[test] @@ -187,7 +187,7 @@ fn test_append_u256_le() { low: 0x100f0e0d0c0b0a090807060504030201_u128, high: 0x201f1e1d1c1b1a191817161514131211_u128, }; ba.append_u256_le(word); - assert(ba == test_byte_array_32(), 'u256 differs'); + assert!(ba == test_byte_array_32(), "u256 differs"); } #[test] @@ -198,7 +198,7 @@ fn test_append_u256_le_arr() { low: 0x100f0e0d0c0b0a090807060504030201_u128, high: 0x201f1e1d1c1b1a191817161514131211_u128, }; ba.append_u256_le(word); - assert(ba == test_array_32(), 'u256 differs'); + assert!(ba == test_array_32(), "u256 differs"); } #[test] @@ -213,7 +213,7 @@ fn test_append_u512() { let mut ba: ByteArray = Default::default(); ba.append_u512(test64); - assert(ba == test_byte_array_64(), 'test64 differs'); + assert!(ba == test_byte_array_64(), "test64 differs"); } #[test] @@ -228,7 +228,7 @@ fn test_append_u512_arr() { let mut ba: Array = array![]; ba.append_u512(test64); - assert(ba == test_array_64(), 'test64 differs'); + assert!(ba == test_array_64(), "test64 differs"); } #[test] @@ -243,7 +243,7 @@ fn test_append_u512_le() { let mut ba: ByteArray = Default::default(); ba.append_u512_le(test64); - assert(ba == test_byte_array_64(), 'test64 differs'); + assert!(ba == test_byte_array_64(), "test64 differs"); } #[test] @@ -258,7 +258,7 @@ fn test_append_u512_le_arr() { let mut ba: Array = array![]; ba.append_u512_le(test64); - assert(ba == test_array_64(), 'test64 differs'); + assert!(ba == test_array_64(), "test64 differs"); } #[test] @@ -268,7 +268,7 @@ fn test_append_i8() { ba1.append_i8(127_i8); let mut ba2: ByteArray = Default::default(); ba2.append_byte(0x7f_u8); - assert(ba1 == ba2, 'i8 differs'); + assert!(ba1 == ba2, "i8 differs"); } #[test] @@ -278,7 +278,7 @@ fn test_append_i8_arr() { ba1.append_i8(127_i8); let mut ba2: Array = array![]; ba2.append(0x7f_u8); - assert(ba1 == ba2, 'i8 differs'); + assert!(ba1 == ba2, "i8 differs"); } #[test] @@ -288,7 +288,7 @@ fn test_append_i8_neg() { ba1.append_i8(-128_i8); let mut ba2: ByteArray = Default::default(); ba2.append_byte(0x80_u8); - assert(ba1 == ba2, 'negative i8 differs'); + assert!(ba1 == ba2, "negative i8 differs"); } #[test] @@ -298,7 +298,7 @@ fn test_append_i8_neg_arr() { ba1.append_i8(-128_i8); let mut ba2: Array = array![]; ba2.append(0x80_u8); - assert(ba1 == ba2, 'negative i8 differs'); + assert!(ba1 == ba2, "negative i8 differs"); } #[test] @@ -309,7 +309,7 @@ fn test_append_i16() { ba1.append_i16(0x0304_i16); ba1.append_i16(0x0506_i16); ba1.append_i16(0x0708_i16); - assert(ba1 == test_byte_array_8(), 'i16 differs'); + assert!(ba1 == test_byte_array_8(), "i16 differs"); } #[test] @@ -320,7 +320,7 @@ fn test_append_i16_arr() { ba1.append_i16(0x0304_i16); ba1.append_i16(0x0506_i16); ba1.append_i16(0x0708_i16); - assert(ba1 == test_array_8(), 'i16 differs'); + assert!(ba1 == test_array_8(), "i16 differs"); } #[test] @@ -331,7 +331,7 @@ fn test_append_i16_le() { ba1.append_i16_le(0x0403_i16); ba1.append_i16_le(0x0605_i16); ba1.append_i16_le(0x0807_i16); - assert(ba1 == test_byte_array_8(), 'i16 differs'); + assert!(ba1 == test_byte_array_8(), "i16 differs"); } #[test] @@ -342,7 +342,7 @@ fn test_append_i16_le_arr() { ba1.append_i16_le(0x0403_i16); ba1.append_i16_le(0x0605_i16); ba1.append_i16_le(0x0807_i16); - assert(ba1 == test_array_8(), 'i16 differs'); + assert!(ba1 == test_array_8(), "i16 differs"); } #[test] @@ -357,7 +357,7 @@ fn test_append_i16_neg() { ba1.append_i16(-1_i16); ba1.append_i16(-1_i16); ba1.append_i16(-2_i16); - assert(ba1 == test_byte_array_16_neg(), 'negative i16 differs'); + assert!(ba1 == test_byte_array_16_neg(), "negative i16 differs"); } #[test] @@ -372,7 +372,7 @@ fn test_append_i16_neg_arr() { ba1.append_i16(-1_i16); ba1.append_i16(-1_i16); ba1.append_i16(-2_i16); - assert(ba1 == test_array_16_neg(), 'negative i16 differs'); + assert!(ba1 == test_array_16_neg(), "negative i16 differs"); } #[test] @@ -387,7 +387,7 @@ fn test_append_i16_le_neg() { ba1.append_i16_le(-1_i16); ba1.append_i16_le(-1_i16); ba1.append_i16_le(-257_i16); - assert(ba1 == test_byte_array_16_neg(), 'negative i16 differs'); + assert!(ba1 == test_byte_array_16_neg(), "negative i16 differs"); } #[test] @@ -402,7 +402,7 @@ fn test_append_i16_le_neg_arr() { ba1.append_i16_le(-1_i16); ba1.append_i16_le(-1_i16); ba1.append_i16_le(-257_i16); - assert(ba1 == test_array_16_neg(), 'negative i16 differs'); + assert!(ba1 == test_array_16_neg(), "negative i16 differs"); } #[test] @@ -411,7 +411,7 @@ fn test_append_i32() { let mut ba: ByteArray = Default::default(); ba.append_i32(0x01020304_i32); ba.append_i32(0x05060708_i32); - assert(ba == test_byte_array_8(), 'i32 differs'); + assert!(ba == test_byte_array_8(), "i32 differs"); } #[test] @@ -420,7 +420,7 @@ fn test_append_i32_arr() { let mut ba: Array = array![]; ba.append_i32(0x01020304_i32); ba.append_i32(0x05060708_i32); - assert(ba == test_array_8(), 'i32 differs'); + assert!(ba == test_array_8(), "i32 differs"); } #[test] @@ -429,7 +429,7 @@ fn test_append_i32_le() { let mut ba: ByteArray = Default::default(); ba.append_i32_le(0x04030201_i32); ba.append_i32_le(0x08070605_i32); - assert(ba == test_byte_array_8(), 'i32 differs'); + assert!(ba == test_byte_array_8(), "i32 differs"); } #[test] @@ -438,7 +438,7 @@ fn test_append_i32_le_arr() { let mut ba: Array = array![]; ba.append_i32_le(0x04030201_i32); ba.append_i32_le(0x08070605_i32); - assert(ba == test_array_8(), 'i32 differs'); + assert!(ba == test_array_8(), "i32 differs"); } #[test] @@ -449,7 +449,7 @@ fn test_append_i32_neg() { ba.append_i32(-1_i32); ba.append_i32(-1_i32); ba.append_i32(-2_i32); - assert(ba == test_byte_array_16_neg(), 'negative i32 differs'); + assert!(ba == test_byte_array_16_neg(), "negative i32 differs"); } #[test] #[available_gas(1000000)] @@ -459,7 +459,7 @@ fn test_append_i32_neg_arr() { ba.append_i32(-1_i32); ba.append_i32(-1_i32); ba.append_i32(-2_i32); - assert(ba == test_array_16_neg(), 'negative i32 differs'); + assert!(ba == test_array_16_neg(), "negative i32 differs"); } #[test] @@ -470,7 +470,7 @@ fn test_append_i32_le_neg() { ba.append_i32_le(-1_i32); ba.append_i32_le(-1_i32); ba.append_i32_le(-16777217_i32); - assert(ba == test_byte_array_16_neg(), 'negative i32 differs'); + assert!(ba == test_byte_array_16_neg(), "negative i32 differs"); } #[test] @@ -481,7 +481,7 @@ fn test_append_i32_le_neg_arr() { ba.append_i32_le(-1_i32); ba.append_i32_le(-1_i32); ba.append_i32_le(-16777217_i32); - assert(ba == test_array_16_neg(), 'negative i32 differs'); + assert!(ba == test_array_16_neg(), "negative i32 differs"); } #[test] @@ -490,7 +490,7 @@ fn test_append_i64() { let mut ba: ByteArray = Default::default(); ba.append_i64(0x0102030405060708_i64); ba.append_i64(0x090a0b0c0d0e0f10_i64); - assert(ba == test_byte_array_16(), 'i64 differs'); + assert!(ba == test_byte_array_16(), "i64 differs"); } #[test] @@ -499,7 +499,7 @@ fn test_append_i64_arr() { let mut ba: Array = array![]; ba.append_i64(0x0102030405060708_i64); ba.append_i64(0x090a0b0c0d0e0f10_i64); - assert(ba == test_array_16(), 'i64 differs'); + assert!(ba == test_array_16(), "i64 differs"); } #[test] @@ -508,7 +508,7 @@ fn test_append_i64_le() { let mut ba: ByteArray = Default::default(); ba.append_i64_le(0x0807060504030201_i64); ba.append_i64_le(0x100f0e0d0c0b0a09_i64); - assert(ba == test_byte_array_16(), 'i64 differs'); + assert!(ba == test_byte_array_16(), "i64 differs"); } #[test] @@ -517,7 +517,7 @@ fn test_append_i64_le_arr() { let mut ba: Array = array![]; ba.append_i64_le(0x0807060504030201_i64); ba.append_i64_le(0x100f0e0d0c0b0a09_i64); - assert(ba == test_array_16(), 'i64 differs'); + assert!(ba == test_array_16(), "i64 differs"); } #[test] @@ -526,7 +526,7 @@ fn test_append_i64_neg() { let mut ba: ByteArray = Default::default(); ba.append_i64(-1_i64); ba.append_i64(-2_i64); - assert(ba == test_byte_array_16_neg(), 'negative i64 differs'); + assert!(ba == test_byte_array_16_neg(), "negative i64 differs"); } #[test] @@ -535,7 +535,7 @@ fn test_append_i64_neg_arr() { let mut ba: Array = array![]; ba.append_i64(-1_i64); ba.append_i64(-2_i64); - assert(ba == test_array_16_neg(), 'negative i64 differs'); + assert!(ba == test_array_16_neg(), "negative i64 differs"); } #[test] @@ -544,7 +544,7 @@ fn test_append_i64_le_neg() { let mut ba: ByteArray = Default::default(); ba.append_i64_le(-1_i64); ba.append_i64_le(-72057594037927937_i64); - assert(ba == test_byte_array_16_neg(), 'negative i64 differs'); + assert!(ba == test_byte_array_16_neg(), "negative i64 differs"); } #[test] @@ -553,7 +553,7 @@ fn test_append_i64_le_neg_arr() { let mut ba: Array = array![]; ba.append_i64_le(-1_i64); ba.append_i64_le(-72057594037927937_i64); - assert(ba == test_array_16_neg(), 'negative i64 differs'); + assert!(ba == test_array_16_neg(), "negative i64 differs"); } #[test] @@ -562,7 +562,7 @@ fn test_append_i128() { let mut ba: ByteArray = Default::default(); ba.append_i128(0x0102030405060708090a0b0c0d0e0f10_i128); ba.append_i128(0x1112131415161718191a1b1c1d1e1f20_i128); - assert(ba == test_byte_array_32(), 'i128 differs'); + assert!(ba == test_byte_array_32(), "i128 differs"); } #[test] @@ -571,7 +571,7 @@ fn test_append_i128_arr() { let mut ba: Array = array![]; ba.append_i128(0x0102030405060708090a0b0c0d0e0f10_i128); ba.append_i128(0x1112131415161718191a1b1c1d1e1f20_i128); - assert(ba == test_array_32(), 'i128 differs'); + assert!(ba == test_array_32(), "i128 differs"); } #[test] @@ -580,7 +580,7 @@ fn test_append_i128_le() { let mut ba: ByteArray = Default::default(); ba.append_i128_le(0x100f0e0d0c0b0a090807060504030201_i128); ba.append_i128_le(0x201f1e1d1c1b1a191817161514131211_i128); - assert(ba == test_byte_array_32(), 'i128 differs'); + assert!(ba == test_byte_array_32(), "i128 differs"); } #[test] @@ -589,7 +589,7 @@ fn test_append_i128_le_arr() { let mut ba: Array = array![]; ba.append_i128_le(0x100f0e0d0c0b0a090807060504030201_i128); ba.append_i128_le(0x201f1e1d1c1b1a191817161514131211_i128); - assert(ba == test_array_32(), 'i128 differs'); + assert!(ba == test_array_32(), "i128 differs"); } #[test] @@ -597,7 +597,7 @@ fn test_append_i128_le_arr() { fn test_append_i128_neg() { let mut ba: ByteArray = Default::default(); ba.append_i128(-2_i128); - assert(ba == test_byte_array_16_neg(), 'negative i128 differs'); + assert!(ba == test_byte_array_16_neg(), "negative i128 differs"); } #[test] @@ -605,7 +605,7 @@ fn test_append_i128_neg() { fn test_append_i128_neg_arr() { let mut ba: Array = array![]; ba.append_i128(-2_i128); - assert(ba == test_array_16_neg(), 'negative i128 differs'); + assert!(ba == test_array_16_neg(), "negative i128 differs"); } #[test] @@ -613,7 +613,7 @@ fn test_append_i128_neg_arr() { fn test_append_i128_le_neg() { let mut ba: ByteArray = Default::default(); ba.append_i128_le(-1329227995784915872903807060280344577_i128); - assert(ba == test_byte_array_16_neg(), 'negative i128 differs'); + assert!(ba == test_byte_array_16_neg(), "negative i128 differs"); } #[test] @@ -621,5 +621,5 @@ fn test_append_i128_le_neg() { fn test_append_i128_le_neg_arr() { let mut ba: Array = array![]; ba.append_i128_le(-1329227995784915872903807060280344577_i128); - assert(ba == test_array_16_neg(), 'negative i128 differs'); + assert!(ba == test_array_16_neg(), "negative i128 differs"); } diff --git a/src/data_structures/src/tests/byte_array_ext_test.cairo b/src/data_structures/src/tests/byte_array_ext_test.cairo index 7a6ea06f..1da58653 100644 --- a/src/data_structures/src/tests/byte_array_ext_test.cairo +++ b/src/data_structures/src/tests/byte_array_ext_test.cairo @@ -24,7 +24,7 @@ fn test_byte_array_into_array_u8() { if index == 0x40 { break; } - assert((*array[index]).into() == index + 1, 'unexpected result'); + assert!((*array[index]).into() == index + 1, "unexpected result"); index += 1; } } diff --git a/src/data_structures/src/tests/byte_reader_test.cairo b/src/data_structures/src/tests/byte_reader_test.cairo index 68cceabc..2e34229f 100644 --- a/src/data_structures/src/tests/byte_reader_test.cairo +++ b/src/data_structures/src/tests/byte_reader_test.cairo @@ -5,222 +5,222 @@ use integer::u512; #[available_gas(1000000)] fn test_word_u16() { let word = test_byte_array_64().word_u16(62).unwrap(); - assert(word == 0x3f40_u16, 'word u16 differs'); + assert!(word == 0x3f40_u16, "word u16 differs"); } #[test] #[available_gas(1000000)] fn test_word_u16_arr() { let word = test_array_64().word_u16(62).unwrap(); - assert(word == 0x3f40_u16, 'word u16 differs'); + assert!(word == 0x3f40_u16, "word u16 differs"); } #[test] #[available_gas(1000000)] fn test_word_u16_le() { let word = test_byte_array_64().word_u16_le(62).unwrap(); - assert(word == 0x403f_u16, 'word u16 differs'); + assert!(word == 0x403f_u16, "word u16 differs"); } #[test] #[available_gas(1000000)] fn test_word_u16_le_arr() { let word = test_array_64().word_u16_le(62).unwrap(); - assert(word == 0x403f_u16, 'word u16 differs'); + assert!(word == 0x403f_u16, "word u16 differs"); } #[test] #[available_gas(1000000)] fn test_word_u16_none() { let is_none = test_byte_array_64().word_u16(63).is_none(); - assert(is_none, 'word u16 should be empty'); + assert!(is_none, "word u16 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u16_none_arr() { let is_none = test_array_64().word_u16(63).is_none(); - assert(is_none, 'word u16 should be empty'); + assert!(is_none, "word u16 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u16_le_none() { let is_none = test_byte_array_64().word_u16_le(63).is_none(); - assert(is_none, 'word u16 should be empty'); + assert!(is_none, "word u16 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u16_le_none_arr() { let is_none = test_array_64().word_u16_le(63).is_none(); - assert(is_none, 'word u16 should be empty'); + assert!(is_none, "word u16 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u32() { let word = test_byte_array_64().word_u32(60).unwrap(); - assert(word == 0x3d3e3f40_u32, 'word u32 differs'); + assert!(word == 0x3d3e3f40_u32, "word u32 differs"); } #[test] #[available_gas(1000000)] fn test_word_u32_arr() { let word = test_array_64().word_u32(60).unwrap(); - assert(word == 0x3d3e3f40_u32, 'word u32 differs'); + assert!(word == 0x3d3e3f40_u32, "word u32 differs"); } #[test] #[available_gas(1000000)] fn test_word_u32_le() { let word = test_byte_array_64().word_u32_le(60).unwrap(); - assert(word == 0x403f3e3d_u32, 'word u32 differs'); + assert!(word == 0x403f3e3d_u32, "word u32 differs"); } #[test] #[available_gas(1000000)] fn test_word_u32_le_arr() { let word = test_array_64().word_u32_le(60).unwrap(); - assert(word == 0x403f3e3d_u32, 'word u32 differs'); + assert!(word == 0x403f3e3d_u32, "word u32 differs"); } #[test] #[available_gas(1000000)] fn test_word_u32_none() { let is_none = test_byte_array_64().word_u32(61).is_none(); - assert(is_none, 'word u32 should be empty'); + assert!(is_none, "word u32 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u32_none_arr() { let is_none = test_array_64().word_u32(61).is_none(); - assert(is_none, 'word u32 should be empty'); + assert!(is_none, "word u32 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u32_le_none() { let is_none = test_byte_array_64().word_u32_le(61).is_none(); - assert(is_none, 'word u32 should be empty'); + assert!(is_none, "word u32 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u32_le_none_arr() { let is_none = test_array_64().word_u32_le(61).is_none(); - assert(is_none, 'word u32 should be empty'); + assert!(is_none, "word u32 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u64() { let word = test_byte_array_64().word_u64(56).unwrap(); - assert(word == 0x393a3b3c3d3e3f40_u64, 'word u64 differs'); + assert!(word == 0x393a3b3c3d3e3f40_u64, "word u64 differs"); } #[test] #[available_gas(1000000)] fn test_word_u64_arr() { let word = test_array_64().word_u64(56).unwrap(); - assert(word == 0x393a3b3c3d3e3f40_u64, 'word u64 differs'); + assert!(word == 0x393a3b3c3d3e3f40_u64, "word u64 differs"); } #[test] #[available_gas(1000000)] fn test_word_u64_le() { let word = test_byte_array_64().word_u64_le(56).unwrap(); - assert(word == 0x403f3e3d3c3b3a39_u64, 'word u64 differs'); + assert!(word == 0x403f3e3d3c3b3a39_u64, "word u64 differs"); } #[test] #[available_gas(1000000)] fn test_word_u64_le_arr() { let word = test_array_64().word_u64_le(56).unwrap(); - assert(word == 0x403f3e3d3c3b3a39_u64, 'word u64 differs'); + assert!(word == 0x403f3e3d3c3b3a39_u64, "word u64 differs"); } #[test] #[available_gas(1000000)] fn test_word_u64_none() { let is_none = test_byte_array_64().word_u64(57).is_none(); - assert(is_none, 'word u64 should be empty'); + assert!(is_none, "word u64 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u64_none_arr() { let is_none = test_array_64().word_u64(57).is_none(); - assert(is_none, 'word u64 should be empty'); + assert!(is_none, "word u64 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u64_le_none() { let is_none = test_byte_array_64().word_u64_le(57).is_none(); - assert(is_none, 'word u64 should be empty'); + assert!(is_none, "word u64 should be empty"); } #[test] #[available_gas(1000000)] fn test_word_u64_le_none_arr() { let is_none = test_array_64().word_u64_le(57).is_none(); - assert(is_none, 'word u64 should be empty'); + assert!(is_none, "word u64 should be empty"); } #[test] #[available_gas(2000000)] fn test_word_u128() { let word = test_byte_array_64().word_u128(48).unwrap(); - assert(word == 0x3132333435363738393a3b3c3d3e3f40_u128, 'word u128 differs'); + assert!(word == 0x3132333435363738393a3b3c3d3e3f40_u128, "word u128 differs"); } #[test] #[available_gas(2000000)] fn test_word_u128_arr() { let word = test_array_64().word_u128(48).unwrap(); - assert(word == 0x3132333435363738393a3b3c3d3e3f40_u128, 'word u128 differs'); + assert!(word == 0x3132333435363738393a3b3c3d3e3f40_u128, "word u128 differs"); } #[test] #[available_gas(2000000)] fn test_word_u128_le() { let word = test_byte_array_64().word_u128_le(48).unwrap(); - assert(word == 0x403f3e3d3c3b3a393837363534333231_u128, 'word u128 differs'); + assert!(word == 0x403f3e3d3c3b3a393837363534333231_u128, "word u128 differs"); } #[test] #[available_gas(2000000)] fn test_word_u128_le_arr() { let word = test_array_64().word_u128_le(48).unwrap(); - assert(word == 0x403f3e3d3c3b3a393837363534333231_u128, 'word u128 differs'); + assert!(word == 0x403f3e3d3c3b3a393837363534333231_u128, "word u128 differs"); } #[test] #[available_gas(2000000)] fn test_word_u128_none() { let is_none = test_byte_array_64().word_u128(49).is_none(); - assert(is_none, 'word u128 should be empty'); + assert!(is_none, "word u128 should be empty"); } fn test_word_u128_none_arr() { let is_none = test_array_64().word_u128(49).is_none(); - assert(is_none, 'word u128 should be empty'); + assert!(is_none, "word u128 should be empty"); } #[test] #[available_gas(2000000)] fn test_word_u128_le_none() { let is_none = test_byte_array_64().word_u128_le(49).is_none(); - assert(is_none, 'word u128 should be empty'); + assert!(is_none, "word u128 should be empty"); } #[test] #[available_gas(2000000)] fn test_word_u128_le_none_arr() { let is_none = test_array_64().word_u128_le(49).is_none(); - assert(is_none, 'word u128 should be empty'); + assert!(is_none, "word u128 should be empty"); } #[test] @@ -228,7 +228,7 @@ fn test_word_u128_le_none_arr() { fn test_reader_helper() { let ba = test_byte_array_64(); let reader = ba.reader(); - assert(reader.data == @ba, 'reader failed'); + assert!(reader.data == @ba, "reader failed"); } #[test] @@ -236,7 +236,7 @@ fn test_reader_helper() { fn test_reader_helper_arr() { let ba = test_array_64(); let reader = ba.reader(); - assert(reader.data == @ba, 'reader failed'); + assert!(reader.data == @ba, "reader failed"); } #[test] @@ -244,21 +244,21 @@ fn test_reader_helper_arr() { fn test_len() { let ba = test_byte_array_64(); let mut rd = ba.reader(); - assert(64 == rd.len(), 'expected len 64'); + assert!(64 == rd.len(), "expected len 64"); let _ = rd.read_u8().expect('some'); - assert(63 == rd.len(), 'expected len 63'); + assert!(63 == rd.len(), "expected len 63"); let _ = rd.read_u256().expect('some'); - assert(31 == rd.len(), 'expected len 31'); + assert!(31 == rd.len(), "expected len 31"); let _ = rd.read_u128().expect('some'); - assert(15 == rd.len(), 'expected len 15'); + assert!(15 == rd.len(), "expected len 15"); let _ = rd.read_u64().expect('some'); - assert(7 == rd.len(), 'expected len 7'); + assert!(7 == rd.len(), "expected len 7"); let _ = rd.read_u32().expect('some'); - assert(3 == rd.len(), 'expected len 3'); + assert!(3 == rd.len(), "expected len 3"); let _ = rd.read_u16().expect('some'); - assert(1 == rd.len(), 'expected len 1'); + assert!(1 == rd.len(), "expected len 1"); let _ = rd.read_i8().expect('some'); - assert(0 == rd.len(), 'expected len 0'); + assert!(0 == rd.len(), "expected len 0"); } #[test] @@ -266,21 +266,21 @@ fn test_len() { fn test_len_arr() { let ba = test_array_64(); let mut rd = ba.reader(); - assert(64 == rd.len(), 'expected len 64'); + assert!(64 == rd.len(), "expected len 64"); let _ = rd.read_u8().expect('some'); - assert(63 == rd.len(), 'expected len 63'); + assert!(63 == rd.len(), "expected len 63"); let _ = rd.read_u256().expect('some'); - assert(31 == rd.len(), 'expected len 31'); + assert!(31 == rd.len(), "expected len 31"); let _ = rd.read_u128().expect('some'); - assert(15 == rd.len(), 'expected len 15'); + assert!(15 == rd.len(), "expected len 15"); let _ = rd.read_u64().expect('some'); - assert(7 == rd.len(), 'expected len 7'); + assert!(7 == rd.len(), "expected len 7"); let _ = rd.read_u32().expect('some'); - assert(3 == rd.len(), 'expected len 3'); + assert!(3 == rd.len(), "expected len 3"); let _ = rd.read_u16().expect('some'); - assert(1 == rd.len(), 'expected len 1'); + assert!(1 == rd.len(), "expected len 1"); let _ = rd.read_i8().expect('some'); - assert(0 == rd.len(), 'expected len 0'); + assert!(0 == rd.len(), "expected len 0"); } #[test] @@ -289,8 +289,8 @@ fn test_read_u256() { let ba = test_byte_array_64(); let mut rd = ba.reader(); let u256{low: low1, high: high1 } = rd.read_u256().unwrap(); - assert(high1 == 0x0102030405060708090a0b0c0d0e0f10_u128, 'wrong value for high1'); - assert(low1 == 0x1112131415161718191a1b1c1d1e1f20_u128, 'wrong value for low1'); + assert!(high1 == 0x0102030405060708090a0b0c0d0e0f10_u128, "wrong value for high1"); + assert!(low1 == 0x1112131415161718191a1b1c1d1e1f20_u128, "wrong value for low1"); } #[test] @@ -299,8 +299,8 @@ fn test_read_u256_arr() { let ba = test_array_64(); let mut rd = ba.reader(); let u256{low: low1, high: high1 } = rd.read_u256().unwrap(); - assert(high1 == 0x0102030405060708090a0b0c0d0e0f10_u128, 'wrong value for high1'); - assert(low1 == 0x1112131415161718191a1b1c1d1e1f20_u128, 'wrong value for low1'); + assert!(high1 == 0x0102030405060708090a0b0c0d0e0f10_u128, "wrong value for high1"); + assert!(low1 == 0x1112131415161718191a1b1c1d1e1f20_u128, "wrong value for low1"); } #[test] @@ -309,8 +309,8 @@ fn test_read_u256_le() { let ba = test_byte_array_64(); let mut rd = ba.reader(); let u256{low: low1, high: high1 } = rd.read_u256_le().unwrap(); - assert(high1 == 0x201f1e1d1c1b1a191817161514131211_u128, 'wrong value for high1'); - assert(low1 == 0x100f0e0d0c0b0a090807060504030201_u128, 'wrong value for low1'); + assert!(high1 == 0x201f1e1d1c1b1a191817161514131211_u128, "wrong value for high1"); + assert!(low1 == 0x100f0e0d0c0b0a090807060504030201_u128, "wrong value for low1"); } #[test] @@ -319,8 +319,8 @@ fn test_read_u256_le_arr() { let ba = test_array_64(); let mut rd = ba.reader(); let u256{low: low1, high: high1 } = rd.read_u256_le().unwrap(); - assert(high1 == 0x201f1e1d1c1b1a191817161514131211_u128, 'wrong value for high1'); - assert(low1 == 0x100f0e0d0c0b0a090807060504030201_u128, 'wrong value for low1'); + assert!(high1 == 0x201f1e1d1c1b1a191817161514131211_u128, "wrong value for high1"); + assert!(low1 == 0x100f0e0d0c0b0a090807060504030201_u128, "wrong value for low1"); } #[test] @@ -330,10 +330,10 @@ fn test_read_u512() { let mut rd = ba.reader(); let u512{limb0, limb1, limb2, limb3 } = rd.read_u512().unwrap(); - assert(limb3 == 0x0102030405060708090a0b0c0d0e0f10_u128, 'wrong value for limb3'); - assert(limb2 == 0x1112131415161718191a1b1c1d1e1f20_u128, 'wrong value for limb2'); - assert(limb1 == 0x2122232425262728292a2b2c2d2e2f30_u128, 'wrong value for limb1'); - assert(limb0 == 0x3132333435363738393a3b3c3d3e3f40_u128, 'wrong value for limb0'); + assert!(limb3 == 0x0102030405060708090a0b0c0d0e0f10_u128, "wrong value for limb3"); + assert!(limb2 == 0x1112131415161718191a1b1c1d1e1f20_u128, "wrong value for limb2"); + assert!(limb1 == 0x2122232425262728292a2b2c2d2e2f30_u128, "wrong value for limb1"); + assert!(limb0 == 0x3132333435363738393a3b3c3d3e3f40_u128, "wrong value for limb0"); } #[test] @@ -343,10 +343,10 @@ fn test_read_u512_arr() { let mut rd = ba.reader(); let u512{limb0, limb1, limb2, limb3 } = rd.read_u512().unwrap(); - assert(limb3 == 0x0102030405060708090a0b0c0d0e0f10_u128, 'wrong value for limb3'); - assert(limb2 == 0x1112131415161718191a1b1c1d1e1f20_u128, 'wrong value for limb2'); - assert(limb1 == 0x2122232425262728292a2b2c2d2e2f30_u128, 'wrong value for limb1'); - assert(limb0 == 0x3132333435363738393a3b3c3d3e3f40_u128, 'wrong value for limb0'); + assert!(limb3 == 0x0102030405060708090a0b0c0d0e0f10_u128, "wrong value for limb3"); + assert!(limb2 == 0x1112131415161718191a1b1c1d1e1f20_u128, "wrong value for limb2"); + assert!(limb1 == 0x2122232425262728292a2b2c2d2e2f30_u128, "wrong value for limb1"); + assert!(limb0 == 0x3132333435363738393a3b3c3d3e3f40_u128, "wrong value for limb0"); } #[test] @@ -355,10 +355,10 @@ fn test_read_u512_le() { let ba = test_byte_array_64(); let mut rd = ba.reader(); let u512{limb0, limb1, limb2, limb3 } = rd.read_u512_le().unwrap(); - assert(limb0 == 0x100f0e0d0c0b0a090807060504030201_u128, 'wrong value for limb0'); - assert(limb1 == 0x201f1e1d1c1b1a191817161514131211_u128, 'wrong value for limb1'); - assert(limb2 == 0x302f2e2d2c2b2a292827262524232221_u128, 'wrong value for limb2'); - assert(limb3 == 0x403f3e3d3c3b3a393837363534333231_u128, 'wrong value for limb3'); + assert!(limb0 == 0x100f0e0d0c0b0a090807060504030201_u128, "wrong value for limb0"); + assert!(limb1 == 0x201f1e1d1c1b1a191817161514131211_u128, "wrong value for limb1"); + assert!(limb2 == 0x302f2e2d2c2b2a292827262524232221_u128, "wrong value for limb2"); + assert!(limb3 == 0x403f3e3d3c3b3a393837363534333231_u128, "wrong value for limb3"); } #[test] @@ -367,10 +367,10 @@ fn test_read_u512_le_arr() { let ba = test_array_64(); let mut rd = ba.reader(); let u512{limb0, limb1, limb2, limb3 } = rd.read_u512_le().unwrap(); - assert(limb0 == 0x100f0e0d0c0b0a090807060504030201_u128, 'wrong value for limb0'); - assert(limb1 == 0x201f1e1d1c1b1a191817161514131211_u128, 'wrong value for limb1'); - assert(limb2 == 0x302f2e2d2c2b2a292827262524232221_u128, 'wrong value for limb2'); - assert(limb3 == 0x403f3e3d3c3b3a393837363534333231_u128, 'wrong value for limb3'); + assert!(limb0 == 0x100f0e0d0c0b0a090807060504030201_u128, "wrong value for limb0"); + assert!(limb1 == 0x201f1e1d1c1b1a191817161514131211_u128, "wrong value for limb1"); + assert!(limb2 == 0x302f2e2d2c2b2a292827262524232221_u128, "wrong value for limb2"); + assert!(limb3 == 0x403f3e3d3c3b3a393837363534333231_u128, "wrong value for limb3"); } #[test] @@ -378,21 +378,21 @@ fn test_read_u512_le_arr() { fn test_read_sequence() { let ba = test_byte_array_64(); let mut rd = ba.reader(); - assert(rd.read_i8() == Option::Some(1), 'expected 1'); + assert!(rd.read_i8() == Option::Some(1), "expected 1"); assert( rd.read_i128() == Option::Some(0x02030405060708090a0b0c0d0e0f1011), 'not 0x0203040506...' ); assert( rd.read_u128() == Option::Some(0x12131415161718191a1b1c1d1e1f2021), 'not 0x1213141516...' ); - assert(rd.read_i64() == Option::Some(0x2223242526272829), 'not 0x22232425...'); + assert!(rd.read_i64() == Option::Some(0x2223242526272829), "not 0x22232425..."); assert( rd.read_u128() == Option::Some(0x2a2b2c2d2e2f30313233343536373839), 'not 0x2a2b2c2d2e...' ); - assert(rd.read_u32() == Option::Some(0x3a3b3c3d), 'not 0x3a3b3c3d'); - assert(rd.read_i16() == Option::Some(0x3e3f), 'not 0x3e3f'); - assert(rd.read_u8() == Option::Some(0x40), 'not 0x40'); - assert(rd.read_u8().is_none(), 'expected none'); + assert!(rd.read_u32() == Option::Some(0x3a3b3c3d), "not 0x3a3b3c3d"); + assert!(rd.read_i16() == Option::Some(0x3e3f), "not 0x3e3f"); + assert!(rd.read_u8() == Option::Some(0x40), "not 0x40"); + assert!(rd.read_u8().is_none(), "expected none"); } #[test] @@ -400,21 +400,21 @@ fn test_read_sequence() { fn test_read_sequence_arr() { let ba = test_array_64(); let mut rd = ba.reader(); - assert(rd.read_i8() == Option::Some(1), 'expected 1'); + assert!(rd.read_i8() == Option::Some(1), "expected 1"); assert( rd.read_i128() == Option::Some(0x02030405060708090a0b0c0d0e0f1011), 'not 0x0203040506...' ); assert( rd.read_u128() == Option::Some(0x12131415161718191a1b1c1d1e1f2021), 'not 0x1213141516...' ); - assert(rd.read_i64() == Option::Some(0x2223242526272829), 'not 0x22232425...'); + assert!(rd.read_i64() == Option::Some(0x2223242526272829), "not 0x22232425..."); assert( rd.read_u128() == Option::Some(0x2a2b2c2d2e2f30313233343536373839), 'not 0x2a2b2c2d2e...' ); - assert(rd.read_u32() == Option::Some(0x3a3b3c3d), 'not 0x3a3b3c3d'); - assert(rd.read_i16() == Option::Some(0x3e3f), 'not 0x3e3f'); - assert(rd.read_u8() == Option::Some(0x40), 'not 0x40'); - assert(rd.read_u8().is_none(), 'expected none'); + assert!(rd.read_u32() == Option::Some(0x3a3b3c3d), "not 0x3a3b3c3d"); + assert!(rd.read_i16() == Option::Some(0x3e3f), "not 0x3e3f"); + assert!(rd.read_u8() == Option::Some(0x40), "not 0x40"); + assert!(rd.read_u8().is_none(), "expected none"); } #[test] @@ -422,21 +422,21 @@ fn test_read_sequence_arr() { fn test_read_sequence_le() { let ba = test_byte_array_64(); let mut rd = ba.reader(); - assert(rd.read_i8() == Option::Some(1), 'expected 1'); + assert!(rd.read_i8() == Option::Some(1), "expected 1"); assert( rd.read_i128_le() == Option::Some(0x11100f0e0d0c0b0a0908070605040302), 'not 0x11100f0e0...' ); assert( rd.read_u128_le() == Option::Some(0x21201f1e1d1c1b1a1918171615141312), 'not 0x21201f1e1d...' ); - assert(rd.read_i64_le() == Option::Some(0x2928272625242322), 'not 0x29282726...'); + assert!(rd.read_i64_le() == Option::Some(0x2928272625242322), "not 0x29282726..."); assert( rd.read_u128_le() == Option::Some(0x393837363534333231302f2e2d2c2b2a), 'not 0x3938373635...' ); - assert(rd.read_u32_le() == Option::Some(0x3d3c3b3a), 'not 0x3d3c3b3a'); - assert(rd.read_i16_le() == Option::Some(0x3f3e), 'not 0x3f3e'); - assert(rd.read_u8() == Option::Some(0x40), 'not 0x40'); - assert(rd.read_u8().is_none(), 'expected none'); + assert!(rd.read_u32_le() == Option::Some(0x3d3c3b3a), "not 0x3d3c3b3a"); + assert!(rd.read_i16_le() == Option::Some(0x3f3e), "not 0x3f3e"); + assert!(rd.read_u8() == Option::Some(0x40), "not 0x40"); + assert!(rd.read_u8().is_none(), "expected none"); } #[test] @@ -444,21 +444,21 @@ fn test_read_sequence_le() { fn test_read_sequence_le_arr() { let ba = test_array_64(); let mut rd = ba.reader(); - assert(rd.read_i8() == Option::Some(1), 'expected 1'); + assert!(rd.read_i8() == Option::Some(1), "expected 1"); assert( rd.read_i128_le() == Option::Some(0x11100f0e0d0c0b0a0908070605040302), 'not 0x11100f0e0...' ); assert( rd.read_u128_le() == Option::Some(0x21201f1e1d1c1b1a1918171615141312), 'not 0x21201f1e1d...' ); - assert(rd.read_i64_le() == Option::Some(0x2928272625242322), 'not 0x29282726...'); + assert!(rd.read_i64_le() == Option::Some(0x2928272625242322), "not 0x29282726..."); assert( rd.read_u128_le() == Option::Some(0x393837363534333231302f2e2d2c2b2a), 'not 0x3938373635...' ); - assert(rd.read_u32_le() == Option::Some(0x3d3c3b3a), 'not 0x3d3c3b3a'); - assert(rd.read_i16_le() == Option::Some(0x3f3e), 'not 0x3f3e'); - assert(rd.read_u8() == Option::Some(0x40), 'not 0x40'); - assert(rd.read_u8().is_none(), 'expected none'); + assert!(rd.read_u32_le() == Option::Some(0x3d3c3b3a), "not 0x3d3c3b3a"); + assert!(rd.read_i16_le() == Option::Some(0x3f3e), "not 0x3f3e"); + assert!(rd.read_u8() == Option::Some(0x40), "not 0x40"); + assert!(rd.read_u8().is_none(), "expected none"); } #[test] @@ -468,10 +468,10 @@ fn test_clone_byte_array_reader() { let mut rd1 = ba.reader(); let mut rd2 = rd1.clone(); let a = rd1.read_u128().unwrap(); - assert(rd1.index != rd2.index, 'indicies equal'); + assert!(rd1.index != rd2.index, "indicies equal"); let b = rd2.read_u128().unwrap(); - assert(rd1.index == rd2.index, 'indicies not equal'); - assert(a == b, 'copy ByteArrayReader failed'); + assert!(rd1.index == rd2.index, "indicies not equal"); + assert!(a == b, "copy ByteArrayReader failed"); } #[test] @@ -481,10 +481,10 @@ fn test_clone_array_of_bytes_reader() { let mut rd1 = ba.reader(); let mut rd2 = rd1.clone(); let a = rd1.read_u128().unwrap(); - assert(rd1.index != rd2.index, 'indicies equal'); + assert!(rd1.index != rd2.index, "indicies equal"); let b = rd2.read_u128().unwrap(); - assert(rd1.index == rd2.index, 'indicies not equal'); - assert(a == b, 'copy ByteArrayReader failed'); + assert!(rd1.index == rd2.index, "indicies not equal"); + assert!(a == b, "copy ByteArrayReader failed"); } #[test] @@ -492,11 +492,11 @@ fn test_clone_array_of_bytes_reader() { fn test_byte_array_reader_equals_array_of_bytes_reader() { let mut ba = test_array_64().reader(); let mut bb = test_byte_array_64().reader(); - assert(ba.read_u16() == bb.read_u16(), 'not equal'); - assert(ba.read_u16_le() == bb.read_u16_le(), 'not equal'); - assert(ba.read_i16() == bb.read_i16(), 'not equal'); - assert(ba.read_i16_le() == bb.read_i16_le(), 'not equal'); - assert(ba.read_u256() == bb.read_u256(), 'not equal'); + assert!(ba.read_u16() == bb.read_u16(), "not equal"); + assert!(ba.read_u16_le() == bb.read_u16_le(), "not equal"); + assert!(ba.read_i16() == bb.read_i16(), "not equal"); + assert!(ba.read_i16_le() == bb.read_i16_le(), "not equal"); + assert!(ba.read_u256() == bb.read_u256(), "not equal"); } // helpers @@ -541,17 +541,15 @@ fn test_byte_array_64() -> ByteArray { } fn test_array_8() -> Array { - let mut ba1 = array![1, 2, 3, 4, 5, 6, 7, 8]; - ba1 + array![1, 2, 3, 4, 5, 6, 7, 8] } fn test_array_16() -> Array { - let mut ba1 = array![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - ba1 + array![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] } fn test_array_32() -> Array { - let mut ba1 = array![ + array![ 1, 2, 3, @@ -584,12 +582,11 @@ fn test_array_32() -> Array { 30, 31, 32 - ]; - ba1 + ] } fn test_array_32_neg() -> Array { - let mut ba1 = array![ + array![ 0xff, 0xfe, 0xfd, @@ -622,12 +619,11 @@ fn test_array_32_neg() -> Array { 0xe2, 0xe1, 0xe0 - ]; - ba1 + ] } fn test_array_16_neg() -> Array { - let mut ba1 = array![ + array![ 0xff, 0xff, 0xff, @@ -644,12 +640,11 @@ fn test_array_16_neg() -> Array { 0xff, 0xff, 0xfe - ]; - ba1 + ] } fn test_array_64() -> Array { - let mut ba1 = array![ + array![ 1, 2, 3, @@ -714,8 +709,7 @@ fn test_array_64() -> Array { 62, 63, 64 - ]; - ba1 + ] } diff --git a/src/data_structures/src/tests/queue_test.cairo b/src/data_structures/src/tests/queue_test.cairo index 24962615..90b73208 100644 --- a/src/data_structures/src/tests/queue_test.cairo +++ b/src/data_structures/src/tests/queue_test.cairo @@ -3,19 +3,19 @@ use alexandria_data_structures::queue::{Queue, QueueTrait}; #[test] #[available_gas(2000000)] fn queue_new_test() { - let mut queue = QueueTrait::::new(); + let queue = QueueTrait::::new(); let result_len = queue.len(); - assert(result_len == 0, 'wrong length'); + assert_eq!(result_len, 0, "wrong length"); } #[test] #[available_gas(2000000)] fn queue_is_empty_test() { - let mut queue = QueueTrait::::new(); + let queue = QueueTrait::::new(); let result = queue.is_empty(); - assert(result, 'should be empty'); + assert!(result, "should be empty"); } #[test] @@ -25,8 +25,8 @@ fn queue_enqueue_test() { queue.enqueue(1); queue.enqueue(2); - assert(!queue.is_empty(), 'must not be empty'); - assert(queue.len() == 2, 'len should be 2'); + assert!(!queue.is_empty(), "must not be empty"); + assert_eq!(queue.len(), 2, "len should be 2"); } #[test] @@ -38,12 +38,12 @@ fn queue_peek_front_test() { queue.enqueue(3); match queue.peek_front() { - Option::Some(result) => { assert(*(result.unbox()) == 1, 'wrong result'); }, - Option::None => { assert(false, 'should return value'); }, + Option::Some(result) => { assert_eq!(*(result.unbox()), 1, "wrong result"); }, + Option::None => { assert!(false, "should return value"); }, }; let result_len = queue.len(); - assert(result_len == 3, 'should not remove items'); + assert_eq!(result_len, 3, "should not remove items"); } #[test] @@ -55,10 +55,10 @@ fn queue_dequeue_test() { queue.enqueue(3); match queue.dequeue() { - Option::Some(result) => { assert(result == 1, 'wrong result'); }, - Option::None => { assert(false, 'should return a value'); }, + Option::Some(result) => { assert_eq!(result, 1, "wrong result"); }, + Option::None => { assert!(false, "should return a value"); }, }; let result_len = queue.len(); - assert(result_len == 2, 'should remove item'); + assert_eq!(result_len, 2, "should remove item"); } diff --git a/src/data_structures/src/tests/stack_test.cairo b/src/data_structures/src/tests/stack_test.cairo index a9a7bcd8..0fb94a88 100644 --- a/src/data_structures/src/tests/stack_test.cairo +++ b/src/data_structures/src/tests/stack_test.cairo @@ -3,11 +3,11 @@ use alexandria_data_structures::stack::{StackTrait, Felt252Stack, NullableStack} fn stack_new_test>(stack: @S) { - assert(stack.len() == 0, 'stack length should be 0'); + assert!(stack.len() == 0, "stack length should be 0"); } fn stack_is_empty_test>(stack: @S) { - assert(stack.is_empty(), 'stack should be empty'); + assert!(stack.is_empty(), "stack should be empty"); } fn stack_push_test, +Drop, impl SDestruct: Destruct>( @@ -16,8 +16,8 @@ fn stack_push_test, +Drop, impl SDestruct: stack.push(val_1); stack.push(val_2); - assert(!stack.is_empty(), 'must not be empty'); - assert(stack.len() == 2, 'len should be 2'); + assert!(!stack.is_empty(), "must not be empty"); + assert!(stack.len() == 2, "len should be 2"); } fn stack_peek_test< @@ -34,11 +34,11 @@ fn stack_peek_test< stack.push(val_1); stack.push(val_2); match stack.peek() { - Option::Some(result) => { assert(result == val_2, 'wrong result'); }, - Option::None => { assert(false, 'should return value'); }, + Option::Some(result) => { assert!(result == val_2, "wrong result"); }, + Option::None => { assert!(false, "should return value"); }, }; - assert(stack.len() == 2, 'should not remove items'); + assert!(stack.len() == 2, "should not remove items"); } fn stack_pop_test< @@ -57,11 +57,11 @@ fn stack_pop_test< let value = stack.pop(); match value { - Option::Some(result) => { assert(result == val_2, 'wrong result'); }, - Option::None => { assert(false, 'should return a value'); }, + Option::Some(result) => { assert!(result == val_2, "wrong result"); }, + Option::None => { assert!(false, "should return a value"); }, }; - assert(stack.len() == 1, 'should remove item'); + assert!(stack.len() == 1, "should remove item"); } fn stack_push_pop_push_test< @@ -80,8 +80,8 @@ fn stack_push_pop_push_test< let _ = stack.pop(); stack.push(val_3); - assert(stack.peek().unwrap() == val_3, 'wrong result'); - assert(stack.len() == 2, 'should update length'); + assert!(stack.peek().unwrap() == val_3, "wrong result"); + assert!(stack.len() == 2, "should update length"); } #[test] diff --git a/src/data_structures/src/tests/vec_test.cairo b/src/data_structures/src/tests/vec_test.cairo index 4bb2b22c..59ab35a3 100644 --- a/src/data_structures/src/tests/vec_test.cairo +++ b/src/data_structures/src/tests/vec_test.cairo @@ -2,7 +2,7 @@ use alexandria_data_structures::vec::{Felt252Vec, NullableVec, VecTrait}; fn vec_new_test>(vec: @V) { - assert(vec.len() == 0, 'vec length should be 0'); + assert!(vec.len() == 0, "vec length should be 0"); } fn vec_len_test< @@ -11,7 +11,7 @@ fn vec_len_test< ref vec: V, val_1: T ) { vec.push(val_1); - assert(vec.len() == 1, 'vec length should be 1'); + assert!(vec.len() == 1, "vec length should be 1"); } fn vec_get_test< @@ -20,8 +20,8 @@ fn vec_get_test< ref vec: V, val_1: T ) { vec.push(val_1); - assert(vec.get(0).unwrap() == val_1, 'vec get should return val_1'); - assert(vec.get(1).is_none(), 'vec get should return none'); + assert!(vec.get(0).unwrap() == val_1, "vec get should return val_1"); + assert!(vec.get(1).is_none(), "vec get should return none"); } fn vec_at_test< @@ -30,7 +30,7 @@ fn vec_at_test< ref vec: V, val_1: T ) { vec.push(val_1); - assert(vec.at(0) == val_1, 'vec at should return val_1'); + assert!(vec.at(0) == val_1, "vec at should return val_1"); } fn vec_at_out_of_bounds_test< @@ -47,8 +47,8 @@ fn vec_push_test< ref vec: V, val_1: T ) { vec.push(val_1); - assert(vec.len() == 1, 'vec length should be 1'); - assert(vec.at(0) == val_1, 'vec get should return val_1'); + assert!(vec.len() == 1, "vec length should be 1"); + assert!(vec.at(0) == val_1, "vec get should return val_1"); } fn vec_set_test< @@ -59,7 +59,7 @@ fn vec_set_test< vec.push(val_1); vec.set(0, val_2); let result = vec.get(0); - assert(result.unwrap() == val_2, 'vec get should return val_2'); + assert!(result.unwrap() == val_2, "vec get should return val_2"); } fn vec_set_test_expect_error< @@ -85,8 +85,8 @@ fn vec_index_trait_test< ) { vec.push(val_1); vec.push(val_2); - assert(vec[0] == val_1, 'vec[0] != val_1'); - assert(vec[1] == val_2, 'vec[1] != val_2'); + assert!(vec[0] == val_1, "vec[0] != val_1"); + assert!(vec[1] == val_2, "vec[1] != val_2"); } fn vec_index_trait_out_of_bounds_test< diff --git a/src/encoding/src/reversible.cairo b/src/encoding/src/reversible.cairo index 6a254178..2dcd47b9 100644 --- a/src/encoding/src/reversible.cairo +++ b/src/encoding/src/reversible.cairo @@ -46,10 +46,7 @@ fn reversing_partial_result< mut word: T, mut onto: T, size: usize, step: T ) -> (T, T) { let mut i: usize = 0; - loop { - if i == size { - break; - } + while i != size { let (new_word, remainder) = DivRem::div_rem(word, step.try_into().unwrap()); word = new_word; onto *= step.into(); diff --git a/src/encoding/src/tests/base64_felt_test.cairo b/src/encoding/src/tests/base64_felt_test.cairo index cac7215c..40eb66e5 100644 --- a/src/encoding/src/tests/base64_felt_test.cairo +++ b/src/encoding/src/tests/base64_felt_test.cairo @@ -34,7 +34,7 @@ fn base64encode_empty_test() { let input = 0; let result = Base64FeltEncoder::encode(input); let check = Base64Encoder::encode(bytes_be(input)); - assert(result == check, 'Expected equal'); + assert_eq!(result, check, "Expected equal"); } #[test] @@ -43,7 +43,7 @@ fn base64encode_simple_test() { let input = 'a'; let result = Base64FeltEncoder::encode(input); let check = Base64Encoder::encode(bytes_be(input)); - assert(result == check, 'Expected equal'); + assert_eq!(result, check, "Expected equal"); } #[test] @@ -52,7 +52,7 @@ fn base64encode_hello_world_test() { let input = 'hello world'; let result = Base64FeltEncoder::encode(input); let check = Base64Encoder::encode(bytes_be(input)); - assert(result == check, 'Expected equal'); + assert_eq!(result, check, "Expected equal"); } @@ -63,7 +63,7 @@ fn base64encode_with_plus_and_slash() { let result = Base64FeltEncoder::encode(input); let check = Base64Encoder::encode(bytes_be(input)); - assert(result == check, 'Expected equal'); + assert_eq!(result, check, "Expected equal"); } #[test] @@ -73,5 +73,5 @@ fn base64urlencode_with_plus_and_slash() { let result = Base64UrlFeltEncoder::encode(input); let check = Base64UrlEncoder::encode(bytes_be(input)); - assert(result == check, 'Expected equal'); + assert_eq!(result, check, "Expected equal"); } diff --git a/src/encoding/src/tests/base64_test.cairo b/src/encoding/src/tests/base64_test.cairo index 27602833..5b1be4fb 100644 --- a/src/encoding/src/tests/base64_test.cairo +++ b/src/encoding/src/tests/base64_test.cairo @@ -3,134 +3,134 @@ use alexandria_encoding::base64::{Base64Encoder, Base64Decoder, Base64UrlEncoder #[test] #[available_gas(2000000000)] fn base64encode_empty_test() { - let mut input = array![]; + let input = array![]; let result = Base64Encoder::encode(input); - assert(result.len() == 0, 'invalid result length'); + assert_eq!(result.len(), 0, "invalid result length"); } #[test] #[available_gas(2000000000)] fn base64encode_simple_test() { - let mut input = array!['a']; + let input = array!['a']; let result = Base64Encoder::encode(input); - assert(result.len() == 4, 'invalid result length'); - assert(*result[0] == 'Y', 'invalid result[0]'); - assert(*result[1] == 'Q', 'invalid result[1]'); - assert(*result[2] == '=', 'invalid result[2]'); - assert(*result[3] == '=', 'invalid result[3]'); + assert_eq!(result.len(), 4, "invalid result length"); + assert_eq!(*result[0], 'Y', "invalid result[0]"); + assert_eq!(*result[1], 'Q', "invalid result[1]"); + assert_eq!(*result[2], '=', "invalid result[2]"); + assert_eq!(*result[3], '=', "invalid result[3]"); } #[test] #[available_gas(2000000000)] fn base64encode_hello_world_test() { - let mut input = array!['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']; + let input = array!['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']; let result = Base64Encoder::encode(input); - assert(result.len() == 16, 'invalid result length'); - assert(*result[0] == 'a', 'invalid result[0]'); - assert(*result[1] == 'G', 'invalid result[1]'); - assert(*result[2] == 'V', 'invalid result[2]'); - assert(*result[3] == 's', 'invalid result[3]'); - assert(*result[4] == 'b', 'invalid result[4]'); - assert(*result[5] == 'G', 'invalid result[5]'); - assert(*result[6] == '8', 'invalid result[6]'); - assert(*result[7] == 'g', 'invalid result[7]'); - assert(*result[8] == 'd', 'invalid result[8]'); - assert(*result[9] == '2', 'invalid result[9]'); - assert(*result[10] == '9', 'invalid result[10]'); - assert(*result[11] == 'y', 'invalid result[11]'); - assert(*result[12] == 'b', 'invalid result[12]'); - assert(*result[13] == 'G', 'invalid result[13]'); - assert(*result[14] == 'Q', 'invalid result[14]'); - assert(*result[15] == '=', 'invalid result[15]'); + assert_eq!(result.len(), 16, "invalid result length"); + assert_eq!(*result[0], 'a', "invalid result[0]"); + assert_eq!(*result[1], 'G', "invalid result[1]"); + assert_eq!(*result[2], 'V', "invalid result[2]"); + assert_eq!(*result[3], 's', "invalid result[3]"); + assert_eq!(*result[4], 'b', "invalid result[4]"); + assert_eq!(*result[5], 'G', "invalid result[5]"); + assert_eq!(*result[6], '8', "invalid result[6]"); + assert_eq!(*result[7], 'g', "invalid result[7]"); + assert_eq!(*result[8], 'd', "invalid result[8]"); + assert_eq!(*result[9], '2', "invalid result[9]"); + assert_eq!(*result[10], '9', "invalid result[10]"); + assert_eq!(*result[11], 'y', "invalid result[11]"); + assert_eq!(*result[12], 'b', "invalid result[12]"); + assert_eq!(*result[13], 'G', "invalid result[13]"); + assert_eq!(*result[14], 'Q', "invalid result[14]"); + assert_eq!(*result[15], '=', "invalid result[15]"); } #[test] #[available_gas(2000000000)] fn base64decode_empty_test() { - let mut input = array![]; + let input = array![]; let result = Base64Decoder::decode(input); - assert(result.len() == 0, 'invalid result length'); + assert_eq!(result.len(), 0, "invalid result length"); } #[test] #[available_gas(2000000000)] fn base64decode_simple_test() { - let mut input = array!['Y', 'Q', '=', '=']; + let input = array!['Y', 'Q', '=', '=']; let result = Base64Decoder::decode(input); - assert(result.len() == 1, 'invalid result length'); - assert(*result[0] == 'a', 'invalid result[0]'); + assert_eq!(result.len(), 1, "invalid result length"); + assert_eq!(*result[0], 'a', "invalid result[0]"); } #[test] #[available_gas(2000000000)] fn base64decode_hello_world_test() { - let mut input = array![ + let input = array![ 'a', 'G', 'V', 's', 'b', 'G', '8', 'g', 'd', '2', '9', 'y', 'b', 'G', 'Q', '=' ]; let result = Base64Decoder::decode(input); - assert(result.len() == 11, 'invalid result length'); - assert(*result[0] == 'h', 'invalid result[0]'); - assert(*result[1] == 'e', 'invalid result[1]'); - assert(*result[2] == 'l', 'invalid result[2]'); - assert(*result[3] == 'l', 'invalid result[3]'); - assert(*result[4] == 'o', 'invalid result[4]'); - assert(*result[5] == ' ', 'invalid result[5]'); - assert(*result[6] == 'w', 'invalid result[6]'); - assert(*result[7] == 'o', 'invalid result[7]'); - assert(*result[8] == 'r', 'invalid result[8]'); - assert(*result[9] == 'l', 'invalid result[9]'); - assert(*result[10] == 'd', 'invalid result[10]'); + assert_eq!(result.len(), 11, "invalid result length"); + assert_eq!(*result[0], 'h', "invalid result[0]"); + assert_eq!(*result[1], 'e', "invalid result[1]"); + assert_eq!(*result[2], 'l', "invalid result[2]"); + assert_eq!(*result[3], 'l', "invalid result[3]"); + assert_eq!(*result[4], 'o', "invalid result[4]"); + assert_eq!(*result[5], ' ', "invalid result[5]"); + assert_eq!(*result[6], 'w', "invalid result[6]"); + assert_eq!(*result[7], 'o', "invalid result[7]"); + assert_eq!(*result[8], 'r', "invalid result[8]"); + assert_eq!(*result[9], 'l', "invalid result[9]"); + assert_eq!(*result[10], 'd', "invalid result[10]"); } #[test] #[available_gas(2000000000)] fn base64encode_with_plus_and_slash() { - let mut input = array![255, 239]; + let input = array![255, 239]; let result = Base64Encoder::encode(input); - assert(result.len() == 4, 'invalid result length'); - assert(*result[0] == '/', 'invalid result[0]'); - assert(*result[1] == '+', 'invalid result[1]'); - assert(*result[2] == '8', 'invalid result[2]'); - assert(*result[3] == '=', 'invalid result[3]'); + assert_eq!(result.len(), 4, "invalid result length"); + assert_eq!(*result[0], '/', "invalid result[0]"); + assert_eq!(*result[1], '+', "invalid result[1]"); + assert_eq!(*result[2], '8', "invalid result[2]"); + assert_eq!(*result[3], '=', "invalid result[3]"); } #[test] #[available_gas(2000000000)] fn base64urlencode_with_plus_and_slash() { - let mut input = array![255, 239]; + let input = array![255, 239]; let result = Base64UrlEncoder::encode(input); - assert(result.len() == 4, 'invalid result length'); - assert(*result[0] == '_', 'invalid result[0]'); - assert(*result[1] == '-', 'invalid result[1]'); - assert(*result[2] == '8', 'invalid result[2]'); - assert(*result[3] == '=', 'invalid result[3]'); + assert_eq!(result.len(), 4, "invalid result length"); + assert_eq!(*result[0], '_', "invalid result[0]"); + assert_eq!(*result[1], '-', "invalid result[1]"); + assert_eq!(*result[2], '8', "invalid result[2]"); + assert_eq!(*result[3], '=', "invalid result[3]"); } #[test] #[available_gas(2000000000)] fn base64decode_with_plus_and_slash() { - let mut input = array!['/', '+', '8', '=']; + let input = array!['/', '+', '8', '=']; let result = Base64UrlDecoder::decode(input); - assert(result.len() == 2, 'invalid result length'); - assert(*result[0] == 255, 'invalid result[0]'); - assert(*result[1] == 239, 'invalid result[1]'); + assert_eq!(result.len(), 2, "invalid result length"); + assert_eq!(*result[0], 255, "invalid result[0]"); + assert_eq!(*result[1], 239, "invalid result[1]"); } #[test] #[available_gas(2000000000)] fn base64urldecode_with_plus_and_slash() { - let mut input = array!['_', '-', '8', '=']; + let input = array!['_', '-', '8', '=']; let result = Base64UrlDecoder::decode(input); - assert(result.len() == 2, 'invalid result length'); - assert(*result[0] == 255, 'invalid result[0]'); - assert(*result[1] == 239, 'invalid result[1]'); + assert_eq!(result.len(), 2, "invalid result length"); + assert_eq!(*result[0], 255, "invalid result[0]"); + assert_eq!(*result[1], 239, "invalid result[1]"); } diff --git a/src/encoding/src/tests/reversible_test.cairo b/src/encoding/src/tests/reversible_test.cairo index 637f4f30..a2ae6a1d 100644 --- a/src/encoding/src/tests/reversible_test.cairo +++ b/src/encoding/src/tests/reversible_test.cairo @@ -6,8 +6,8 @@ use integer::u512; fn test_reverse_bytes_u8() { let t: u8 = 0b10111010; let rev = t.reverse_bytes(); - assert(t == rev, 'not equal'); - assert(t == rev.reverse_bytes(), 'not equal'); + assert!(t == rev, "not equal"); + assert!(t == rev.reverse_bytes(), "not equal"); } #[test] @@ -15,8 +15,8 @@ fn test_reverse_bytes_u8() { fn test_reverse_bytes_u16() { let t: u16 = 0x1122; let rev = t.reverse_bytes(); - assert(rev == 0x2211, 'not equal'); - assert(rev.reverse_bytes() == t, 'not equal'); + assert!(rev == 0x2211, "not equal"); + assert!(rev.reverse_bytes() == t, "not equal"); } #[test] @@ -24,8 +24,8 @@ fn test_reverse_bytes_u16() { fn test_reverse_bytes_u32() { let t: u32 = 0x11223344; let rev = t.reverse_bytes(); - assert(rev == 0x44332211, 'not equal'); - assert(rev.reverse_bytes() == t, 'not equal'); + assert!(rev == 0x44332211, "not equal"); + assert!(rev.reverse_bytes() == t, "not equal"); } #[test] @@ -33,8 +33,8 @@ fn test_reverse_bytes_u32() { fn test_reverse_bytes_u64() { let t: u64 = 0x1122334455667788; let rev = t.reverse_bytes(); - assert(rev == 0x8877665544332211, 'not equal'); - assert(rev.reverse_bytes() == t, 'not equal'); + assert!(rev == 0x8877665544332211, "not equal"); + assert!(rev.reverse_bytes() == t, "not equal"); } #[test] @@ -42,8 +42,8 @@ fn test_reverse_bytes_u64() { fn test_reverse_bytes_u128() { let t: u128 = 0x112233445566778899aabbccddeeff00; let rev = t.reverse_bytes(); - assert(rev == 0x00ffeeddccbbaa998877665544332211, 'not equal'); - assert(rev.reverse_bytes() == t, 'not equal'); + assert!(rev == 0x00ffeeddccbbaa998877665544332211, "not equal"); + assert!(rev.reverse_bytes() == t, "not equal"); } #[test] @@ -53,8 +53,8 @@ fn test_reverse_bytes_u256() { let t2: u128 = 0x202122232425262728292a2b2c2d2e2f; let t = u256 { low: t1, high: t2 }; let rev = t.reverse_bytes(); - assert(rev == u256 { low: t2.reverse_bytes(), high: t1.reverse_bytes() }, 'not equal'); - assert(rev.reverse_bytes() == t, 'not equal'); + assert!(rev == u256 { low: t2.reverse_bytes(), high: t1.reverse_bytes() }, "not equal"); + assert!(rev.reverse_bytes() == t, "not equal"); } #[test] @@ -72,8 +72,8 @@ fn test_reverse_bytes_u512() { limb3: t0.reverse_bytes() }; let rev = t.reverse_bytes(); - assert(rev == t_rev, 'not equal'); - assert(rev.reverse_bytes() == t, 'not equal'); + assert!(rev == t_rev, "not equal"); + assert!(rev.reverse_bytes() == t, "not equal"); } #[test] @@ -89,8 +89,8 @@ fn test_reverse_bytes_bytes31() { let t_rev_felt: felt252 = t_rev_u256.try_into().unwrap(); let t_rev: bytes31 = t_rev_felt.try_into().unwrap(); let rev = t.reverse_bytes(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bytes() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bytes() == t, "not equal"); } #[test] @@ -99,8 +99,8 @@ fn test_reverse_bytes_array() { let t: Array = array![0x1122, 0x3344, 0x5566, 0x7788, 0x99aa, 0xbbcc, 0xddee]; let t_rev: Array = array![0xeedd, 0xccbb, 0xaa99, 0x8877, 0x6655, 0x4433, 0x2211]; let rev = t.reverse_bytes(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bytes() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bytes() == t, "not equal"); } #[test] @@ -109,8 +109,8 @@ fn test_reverse_bits_u8() { let t: u8 = 0b10111010; let t_rev: u8 = 0b01011101; let rev = t.reverse_bits(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bits() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bits() == t, "not equal"); } #[test] @@ -119,8 +119,8 @@ fn test_reverse_bits_u16() { let t: u16 = 0x11aa; let t_rev: u16 = 0x5588; let rev = t.reverse_bits(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bits() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bits() == t, "not equal"); } #[test] @@ -129,8 +129,8 @@ fn test_reverse_bits_u32() { let t: u32 = 0x1111aaaa; let t_rev: u32 = 0x55558888; let rev = t.reverse_bits(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bits() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bits() == t, "not equal"); } #[test] @@ -139,8 +139,8 @@ fn test_reverse_bits_u64() { let t: u64 = 0x11111111aaaaaaaa; let t_rev: u64 = 0x5555555588888888; let rev = t.reverse_bits(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bits() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bits() == t, "not equal"); } #[test] @@ -149,8 +149,8 @@ fn test_reverse_bits_u128() { let t: u128 = 0x1111111111111111aaaaaaaaaaaaaaaa; let t_rev: u128 = 0x55555555555555558888888888888888; let rev = t.reverse_bits(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bits() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bits() == t, "not equal"); } #[test] @@ -163,8 +163,8 @@ fn test_reverse_bits_u256() { low: 0xeeeeeeeeeeeeeeee3333333333333333, high: 0x55555555555555558888888888888888, }; let rev = t.reverse_bits(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bits() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bits() == t, "not equal"); } #[test] @@ -182,8 +182,8 @@ fn test_reverse_bits_u512() { limb3: t0.reverse_bits(), }; let rev = t.reverse_bits(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bits() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bits() == t, "not equal"); } #[test] @@ -200,8 +200,8 @@ fn test_reverse_bits_bytes31() { let t_rev_felt: felt252 = t_rev_u256.try_into().unwrap(); let t_rev: bytes31 = t_rev_felt.try_into().unwrap(); let rev = t.reverse_bits(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bits() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bits() == t, "not equal"); } #[test] @@ -210,6 +210,6 @@ fn test_reverse_bits_array() { let t: Array = array![0x1234, 0x57bc, 0xde84, 0xc2ae, 0xd3b7]; let t_rev: Array = array![0xedcb, 0x7543, 0x217b, 0x3dea, 0x2c48]; let rev = t.reverse_bits(); - assert(rev == t_rev, 'not equal rev'); - assert(rev.reverse_bits() == t, 'not equal'); + assert!(rev == t_rev, "not equal rev"); + assert!(rev.reverse_bits() == t, "not equal"); } diff --git a/src/encoding/src/tests/rlp_test.cairo b/src/encoding/src/tests/rlp_test.cairo index 3202324a..056cb008 100644 --- a/src/encoding/src/tests/rlp_test.cairo +++ b/src/encoding/src/tests/rlp_test.cairo @@ -6,94 +6,94 @@ use result::ResultTrait; #[test] #[available_gas(99999999)] fn test_rlp_decode_type_byte() { - let mut arr = array![0x78]; + let arr = array![0x78]; let (rlp_type, offset, size) = RLPTrait::decode_type(arr.span()).unwrap(); - assert(rlp_type == RLPType::String, 'Wrong type'); - assert(offset == 0, 'Wrong offset'); - assert(size == 1, 'Wrong size'); + assert!(rlp_type == RLPType::String, "Wrong type"); + assert!(offset == 0, "Wrong offset"); + assert!(size == 1, "Wrong size"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_type_short_string() { - let mut arr = array![0x82]; + let arr = array![0x82]; let (rlp_type, offset, size) = RLPTrait::decode_type(arr.span()).unwrap(); - assert(rlp_type == RLPType::String, 'Wrong type'); - assert(offset == 1, 'Wrong offset'); - assert(size == 2, 'Wrong size'); + assert!(rlp_type == RLPType::String, "Wrong type"); + assert!(offset == 1, "Wrong offset"); + assert!(size == 2, "Wrong size"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_type_long_string() { - let mut arr = array![0xb9, 0x01, 0x02]; + let arr = array![0xb9, 0x01, 0x02]; let (rlp_type, offset, size) = RLPTrait::decode_type(arr.span()).unwrap(); - assert(rlp_type == RLPType::String, 'Wrong type'); - assert(offset == 3, 'Wrong offset'); - assert(size == 258, 'Wrong size'); + assert!(rlp_type == RLPType::String, "Wrong type"); + assert!(offset == 3, "Wrong offset"); + assert!(size == 258, "Wrong size"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_type_short_list() { - let mut arr = array![0xc3]; + let arr = array![0xc3]; let (rlp_type, offset, size) = RLPTrait::decode_type(arr.span()).unwrap(); - assert(rlp_type == RLPType::List, 'Wrong type'); - assert(offset == 1, 'Wrong offset'); - assert(size == 3, 'Wrong size'); + assert!(rlp_type == RLPType::List, "Wrong type"); + assert!(offset == 1, "Wrong offset"); + assert!(size == 3, "Wrong size"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_type_long_list() { - let mut arr = array![0xf9, 0x01, 0x02]; + let arr = array![0xf9, 0x01, 0x02]; let (rlp_type, offset, size) = RLPTrait::decode_type(arr.span()).unwrap(); - assert(rlp_type == RLPType::List, 'Wrong type'); - assert(offset == 3, 'Wrong offset'); - assert(size == 258, 'Wrong size'); + assert!(rlp_type == RLPType::List, "Wrong type"); + assert!(offset == 3, "Wrong offset"); + assert!(size == 258, "Wrong size"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_type_long_list_len_too_short() { - let mut arr = array![0xf9, 0x01]; + let arr = array![0xf9, 0x01]; let res = RLPTrait::decode_type(arr.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::InputTooShort, 'err != InputTooShort'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::InputTooShort, "err != InputTooShort"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_type_long_string_payload_too_long() { - let mut arr = array![0xbf, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02]; + let arr = array![0xbf, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02]; let res = RLPTrait::decode_type(arr.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::PayloadTooLong, 'err != PayloadTooLong'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::PayloadTooLong, "err != PayloadTooLong"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_type_long_list_payload_too_long() { - let mut arr = array![0xfc, 0x01, 0x02, 0x02, 0x02, 0x02]; + let arr = array![0xfc, 0x01, 0x02, 0x02, 0x02, 0x02]; let res = RLPTrait::decode_type(arr.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::PayloadTooLong, 'err != PayloadTooLong'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::PayloadTooLong, "err != PayloadTooLong"); } #[test] @@ -101,20 +101,20 @@ fn test_rlp_decode_type_long_list_payload_too_long() { fn test_rlp_empty() { let res = RLPTrait::decode(ArrayTrait::new().span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::EmptyInput, 'err != EmptyInput'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::EmptyInput, "err != EmptyInput"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_string_default_value() { - let mut arr = array![0x80]; + let arr = array![0x80]; let rlp_item = RLPTrait::decode(arr.span()).unwrap(); let expected = RLPItem::String(array![].span()); - assert(rlp_item.len() == 1, 'item length not 0'); - assert(*rlp_item[0] == expected, 'wrong item'); + assert!(rlp_item.len() == 1, "item length not 0"); + assert!(*rlp_item[0] == expected, "wrong item"); } @@ -126,12 +126,11 @@ fn test_rlp_decode_string() { if i == 0x80 { break; } - let mut arr = ArrayTrait::new(); - arr.append(i); + let arr = array![i]; let res = RLPTrait::decode(arr.span()).unwrap(); - assert(res == array![RLPItem::String(arr.span())].span(), 'Wrong value'); + assert!(res == array![RLPItem::String(arr.span())].span(), "Wrong value"); i += 1; }; @@ -177,14 +176,14 @@ fn test_rlp_decode_short_string() { let _ = arr.pop_front(); let expected_item = array![RLPItem::String(arr.span())].span(); - assert(res == expected_item, 'Wrong value'); + assert!(res == expected_item, "Wrong value"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_short_string_input_too_short() { - let mut arr = array![ + let arr = array![ 0x9b, 0x5a, 0x80, @@ -216,8 +215,8 @@ fn test_rlp_decode_short_string_input_too_short() { let res = RLPTrait::decode(arr.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::InputTooShort, 'err != InputTooShort'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::InputTooShort, "err != InputTooShort"); } #[test] @@ -295,13 +294,13 @@ fn test_rlp_decode_long_string_with_payload_len_on_1_byte() { let _ = arr.pop_front(); let expected_item = array![RLPItem::String(arr.span())].span(); - assert(res == expected_item, 'Wrong value'); + assert!(res == expected_item, "Wrong value"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_long_string_with_input_too_short() { - let mut arr = array![ + let arr = array![ 0xb8, 0x3c, 0xf7, @@ -366,8 +365,8 @@ fn test_rlp_decode_long_string_with_input_too_short() { let res = RLPTrait::decode(arr.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::InputTooShort, 'err != InputTooShort'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::InputTooShort, "err != InputTooShort"); } @@ -646,48 +645,48 @@ fn test_rlp_decode_long_string_with_payload_len_on_2_bytes() { let _ = arr.pop_front(); let expected_item = array![RLPItem::String(arr.span())].span(); - assert(res == expected_item, 'Wrong value'); + assert!(res == expected_item, "Wrong value"); } #[test] #[available_gas(99999999)] fn test_rlp_decode_long_string_with_payload_len_too_short() { - let mut arr = array![0xb9, 0x01,]; + let arr = array![0xb9, 0x01,]; let res = RLPTrait::decode(arr.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::InputTooShort, 'err != InputTooShort'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::InputTooShort, "err != InputTooShort"); } #[test] #[available_gas(99999999999)] fn test_rlp_decode_short_list() { - let mut arr = array![0xc9, 0x83, 0x35, 0x35, 0x35, 0x42, 0x83, 0x45, 0x38, 0x92]; + let arr = array![0xc9, 0x83, 0x35, 0x35, 0x35, 0x42, 0x83, 0x45, 0x38, 0x92]; let res = RLPTrait::decode(arr.span()).unwrap(); - let mut expected_0 = RLPItem::String(array![0x35, 0x35, 0x35].span()); - let mut expected_1 = RLPItem::String(array![0x42].span()); - let mut expected_2 = RLPItem::String(array![0x45, 0x38, 0x92].span()); + let expected_0 = RLPItem::String(array![0x35, 0x35, 0x35].span()); + let expected_1 = RLPItem::String(array![0x42].span()); + let expected_2 = RLPItem::String(array![0x45, 0x38, 0x92].span()); let expected_list = RLPItem::List(array![expected_0, expected_1, expected_2].span()); - assert(res == array![expected_list].span(), 'Wrong value'); + assert!(res == array![expected_list].span(), "Wrong value"); } #[test] #[available_gas(99999999999)] fn test_rlp_decode_short_nested_list() { - let mut arr = array![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]; + let arr = array![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]; let res = RLPTrait::decode(arr.span()).unwrap(); - let mut expected_0 = RLPItem::List(array![].span()); - let mut expected_1 = RLPItem::List(array![expected_0].span()); - let mut expected_2 = RLPItem::List(array![expected_0, expected_1].span()); + let expected_0 = RLPItem::List(array![].span()); + let expected_1 = RLPItem::List(array![expected_0].span()); + let expected_2 = RLPItem::List(array![expected_0, expected_1].span()); let expected = RLPItem::List(array![expected_0, expected_1, expected_2].span()); - assert(res == array![expected].span(), 'Wrong value'); + assert!(res == array![expected].span(), "Wrong value"); } #[test] @@ -697,24 +696,24 @@ fn test_rlp_decode_multi_list() { let res = RLPTrait::decode(arr.span()).unwrap(); - let mut expected_0 = RLPItem::String(array![0x7a, 0x77].span()); - let mut expected_1 = RLPItem::String(array![0x04].span()); - let mut expected_1 = RLPItem::List(array![expected_1].span()); - let mut expected_2 = RLPItem::String(array![0x01].span()); - let mut expected = RLPItem::List(array![expected_0, expected_1, expected_2].span()); + let expected_0 = RLPItem::String(array![0x7a, 0x77].span()); + let expected_1 = RLPItem::String(array![0x04].span()); + let expected_1 = RLPItem::List(array![expected_1].span()); + let expected_2 = RLPItem::String(array![0x01].span()); + let expected = RLPItem::List(array![expected_0, expected_1, expected_2].span()); - assert(res == array![expected].span(), 'Wrong value'); + assert!(res == array![expected].span(), "Wrong value"); } #[test] #[available_gas(99999999999)] fn test_rlp_decode_short_list_with_input_too_short() { - let mut arr = array![0xc9, 0x83, 0x35, 0x35, 0x89, 0x42, 0x83, 0x45, 0x38]; + let arr = array![0xc9, 0x83, 0x35, 0x35, 0x89, 0x42, 0x83, 0x45, 0x38]; let res = RLPTrait::decode(arr.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::InputTooShort, 'err != InputTooShort'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::InputTooShort, "err != InputTooShort"); } #[test] @@ -1256,7 +1255,7 @@ fn test_rlp_decode_long_list() { ]; let res = RLPTrait::decode(arr.span()).unwrap(); - let mut expected_0 = RLPItem::String( + let expected_0 = RLPItem::String( array![ 0x77, 0x70, @@ -1293,7 +1292,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_1 = RLPItem::String( + let expected_1 = RLPItem::String( array![ 0x1e, 0xa3, @@ -1330,7 +1329,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_2 = RLPItem::String( + let expected_2 = RLPItem::String( array![ 0x2c, 0x4c, @@ -1367,7 +1366,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_3 = RLPItem::String( + let expected_3 = RLPItem::String( array![ 0xa9, 0xdc, @@ -1404,7 +1403,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_4 = RLPItem::String( + let expected_4 = RLPItem::String( array![ 0xa9, 0x5f, @@ -1441,7 +1440,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_5 = RLPItem::String( + let expected_5 = RLPItem::String( array![ 0x39, 0xd4, @@ -1478,7 +1477,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_6 = RLPItem::String( + let expected_6 = RLPItem::String( array![ 0x7a, 0xcc, @@ -1515,7 +1514,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_7 = RLPItem::String( + let expected_7 = RLPItem::String( array![ 0x15, 0x35, @@ -1552,7 +1551,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_8 = RLPItem::String( + let expected_8 = RLPItem::String( array![ 0x68, 0x91, @@ -1589,7 +1588,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_9 = RLPItem::String( + let expected_9 = RLPItem::String( array![ 0xdc, 0x36, @@ -1626,7 +1625,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_10 = RLPItem::String( + let expected_10 = RLPItem::String( array![ 0x20, 0xb0, @@ -1663,7 +1662,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_11 = RLPItem::String( + let expected_11 = RLPItem::String( array![ 0x8e, 0xed, @@ -1700,7 +1699,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_12 = RLPItem::String( + let expected_12 = RLPItem::String( array![ 0x79, 0x23, @@ -1737,7 +1736,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_13 = RLPItem::String( + let expected_13 = RLPItem::String( array![ 0x65, 0x34, @@ -1774,7 +1773,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_14 = RLPItem::String( + let expected_14 = RLPItem::String( array![ 0xbf, 0xf9, @@ -1811,7 +1810,7 @@ fn test_rlp_decode_long_list() { ] .span() ); - let mut expected_15 = RLPItem::String( + let expected_15 = RLPItem::String( array![ 0x7f, 0x14, @@ -1849,9 +1848,9 @@ fn test_rlp_decode_long_list() { .span() ); - let mut expected_16 = RLPItem::String(array![].span()); + let expected_16 = RLPItem::String(array![].span()); - let mut expected = array![ + let expected = array![ expected_0, expected_1, expected_2, @@ -1873,7 +1872,7 @@ fn test_rlp_decode_long_list() { let expected_item = RLPItem::List(expected.span()); - assert(res == array![expected_item].span(), 'Wrong value'); + assert!(res == array![expected_item].span(), "Wrong value"); } @@ -1913,42 +1912,42 @@ fn test_rlp_decode_long_list_with_input_too_short() { let res = RLPTrait::decode(arr.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::InputTooShort, 'err != InputTooShort'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::InputTooShort, "err != InputTooShort"); } #[test] #[available_gas(99999999999)] fn test_rlp_decode_long_list_with_len_too_short() { - let mut arr = array![0xf9, 0x02,]; + let arr = array![0xf9, 0x02,]; let res = RLPTrait::decode(arr.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::InputTooShort, 'err != InputTooShort'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::InputTooShort, "err != InputTooShort"); } #[test] #[available_gas(20000000)] fn test_rlp_encode_empty_input_should_fail() { - let mut input = array![]; + let input = array![]; let res = RLPTrait::encode(input.span()); - assert(res.is_err(), 'Should have failed'); - assert(res.unwrap_err() == RLPError::EmptyInput, 'err != EmptyInput'); + assert!(res.is_err(), "Should have failed"); + assert!(res.unwrap_err() == RLPError::EmptyInput, "err != EmptyInput"); } #[test] #[available_gas(20000000)] fn test_rlp_encode_default_value() { - let mut input = RLPItem::String(array![].span()); + let input = RLPItem::String(array![].span()); let res = RLPTrait::encode(array![input].span()).unwrap(); - assert(res.len() == 1, 'wrong len'); - assert(*res[0] == 0x80, 'wrong encoded value'); + assert!(res.len() == 1, "wrong len"); + assert!(*res[0] == 0x80, "wrong encoded value"); } #[test] @@ -1959,8 +1958,8 @@ fn test_rlp_encode_string_single_byte_lt_0x80() { let res = RLPTrait::encode(array![RLPItem::String(input.span())].span()).unwrap(); - assert(res.len() == 1, 'wrong len'); - assert(*res[0] == 0x40, 'wrong encoded value'); + assert!(res.len() == 1, "wrong len"); + assert!(*res[0] == 0x40, "wrong encoded value"); } #[test] @@ -1971,9 +1970,9 @@ fn test_rlp_encode_string_single_byte_ge_0x80() { let res = RLPTrait::encode(array![RLPItem::String(input.span())].span()).unwrap(); - assert(res.len() == 2, 'wrong len'); - assert(*res[0] == 0x81, 'wrong prefix'); - assert(*res[1] == 0x80, 'wrong encoded value'); + assert!(res.len() == 2, "wrong len"); + assert!(*res[0] == 0x81, "wrong prefix"); + assert!(*res[1] == 0x80, "wrong encoded value"); } #[test] @@ -1985,10 +1984,10 @@ fn test_rlp_encode_string_length_between_2_and_55() { let res = RLPTrait::encode(array![RLPItem::String(input.span())].span()).unwrap(); - assert(res.len() == 3, 'wrong len'); - assert(*res[0] == 0x82, 'wrong prefix'); - assert(*res[1] == 0x40, 'wrong first value'); - assert(*res[2] == 0x50, 'wrong second value'); + assert!(res.len() == 3, "wrong len"); + assert!(*res[0] == 0x82, "wrong prefix"); + assert!(*res[1] == 0x40, "wrong first value"); + assert!(*res[2] == 0x50, "wrong second value"); } #[test] @@ -2006,15 +2005,15 @@ fn test_rlp_encode_string_length_exactly_56() { let res = RLPTrait::encode(array![RLPItem::String(input.span())].span()).unwrap(); - assert(res.len() == 58, 'wrong len'); - assert(*res[0] == 0xb8, 'wrong prefix'); - assert(*res[1] == 56, 'wrong string length'); + assert!(res.len() == 58, "wrong len"); + assert!(*res[0] == 0xb8, "wrong prefix"); + assert!(*res[1] == 56, "wrong string length"); let mut i = 2; loop { if i == 58 { break; } - assert(*res[i] == 0x60, 'wrong value in sequence'); + assert!(*res[i] == 0x60, "wrong value in sequence"); i += 1; }; } @@ -2035,15 +2034,15 @@ fn test_rlp_encode_string_length_greater_than_56() { let res = RLPTrait::encode(array![RLPItem::String(input.span())].span()).unwrap(); - assert(res.len() == 62, 'wrong len'); - assert(*res[0] == 0xb8, 'wrong prefix'); - assert(*res[1] == 60, 'wrong length byte'); + assert!(res.len() == 62, "wrong len"); + assert!(*res[0] == 0xb8, "wrong prefix"); + assert!(*res[1] == 60, "wrong length byte"); let mut i = 2; loop { if i == 62 { break; } - assert(*res[i] == 0x70, 'wrong value in sequence'); + assert!(*res[i] == 0x70, "wrong value in sequence"); i += 1; } } @@ -2063,16 +2062,16 @@ fn test_rlp_encode_string_large_bytearray_inputs() { let res = RLPTrait::encode(array![RLPItem::String(input.span())].span()).unwrap(); - assert(res.len() == 503, 'wrong len'); - assert(*res[0] == 0xb9, 'wrong prefix'); - assert(*res[1] == 0x01, 'wrong first length byte'); - assert(*res[2] == 0xF4, 'wrong second length byte'); + assert!(res.len() == 503, "wrong len"); + assert!(*res[0] == 0xb9, "wrong prefix"); + assert!(*res[1] == 0x01, "wrong first length byte"); + assert!(*res[2] == 0xF4, "wrong second length byte"); let mut i = 3; loop { if i == 503 { break; } - assert(*res[i] == 0x70, 'wrong value in sequence'); + assert!(*res[i] == 0x70, "wrong value in sequence"); i += 1; } } @@ -2086,48 +2085,48 @@ fn test_rlp_encode_mutilple_string() { let res = RLPTrait::encode(input.span()).unwrap(); - assert(res.len() == 10, 'wrong len'); - assert(*res[0] == 0x88, 'wrong prefix'); - assert(*res[1] == 0x40, 'wrong first value'); - assert(*res[2] == 0x53, 'wrong second value'); + assert!(res.len() == 10, "wrong len"); + assert!(*res[0] == 0x88, "wrong prefix"); + assert!(*res[1] == 0x40, "wrong first value"); + assert!(*res[2] == 0x53, "wrong second value"); } #[test] #[available_gas(99999999999)] fn test_rlp_encode_short_list() { - let mut string_0 = RLPItem::String(array![0x35, 0x35, 0x35].span()); - let mut string_1 = RLPItem::String(array![0x42].span()); - let mut string_2 = RLPItem::String(array![0x45, 0x38, 0x92].span()); + let string_0 = RLPItem::String(array![0x35, 0x35, 0x35].span()); + let string_1 = RLPItem::String(array![0x42].span()); + let string_2 = RLPItem::String(array![0x45, 0x38, 0x92].span()); let list = RLPItem::List(array![string_0, string_1, string_2].span()); let res = RLPTrait::encode(array![list].span()).unwrap(); let expected = array![0xc9, 0x83, 0x35, 0x35, 0x35, 0x42, 0x83, 0x45, 0x38, 0x92]; - assert(res.len() == 10, 'wrong len'); - assert(res == expected.span(), 'wrong encoded result'); + assert!(res.len() == 10, "wrong len"); + assert!(res == expected.span(), "wrong encoded result"); } #[test] #[available_gas(99999999999)] fn test_rlp_encode_short_nested_list() { - let mut string_0 = RLPItem::List(array![].span()); - let mut string_1 = RLPItem::List(array![string_0].span()); - let mut string_2 = RLPItem::List(array![string_0, string_1].span()); + let string_0 = RLPItem::List(array![].span()); + let string_1 = RLPItem::List(array![string_0].span()); + let string_2 = RLPItem::List(array![string_0, string_1].span()); let list = RLPItem::List(array![string_0, string_1, string_2].span()); let res = RLPTrait::encode(array![list].span()).unwrap(); - let mut expected = array![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]; + let expected = array![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]; - assert(res.len() == 8, 'wrong len'); - assert(res == expected.span(), 'wrong encoded result'); + assert!(res.len() == 8, "wrong len"); + assert!(res == expected.span(), "wrong encoded result"); } #[test] #[available_gas(99999999999)] fn test_rlp_encode_long_list() { - let mut string_0 = RLPItem::String( + let string_0 = RLPItem::String( array![ 0x77, 0x70, @@ -2164,7 +2163,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_1 = RLPItem::String( + let string_1 = RLPItem::String( array![ 0x1e, 0xa3, @@ -2201,7 +2200,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_2 = RLPItem::String( + let string_2 = RLPItem::String( array![ 0x2c, 0x4c, @@ -2238,7 +2237,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_3 = RLPItem::String( + let string_3 = RLPItem::String( array![ 0xa9, 0xdc, @@ -2275,7 +2274,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_4 = RLPItem::String( + let string_4 = RLPItem::String( array![ 0xa9, 0x5f, @@ -2312,7 +2311,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_5 = RLPItem::String( + let string_5 = RLPItem::String( array![ 0x39, 0xd4, @@ -2349,7 +2348,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_6 = RLPItem::String( + let string_6 = RLPItem::String( array![ 0x7a, 0xcc, @@ -2386,7 +2385,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_7 = RLPItem::String( + let string_7 = RLPItem::String( array![ 0x15, 0x35, @@ -2423,7 +2422,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_8 = RLPItem::String( + let string_8 = RLPItem::String( array![ 0x68, 0x91, @@ -2460,7 +2459,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_9 = RLPItem::String( + let string_9 = RLPItem::String( array![ 0xdc, 0x36, @@ -2497,7 +2496,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_10 = RLPItem::String( + let string_10 = RLPItem::String( array![ 0x20, 0xb0, @@ -2534,7 +2533,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_11 = RLPItem::String( + let string_11 = RLPItem::String( array![ 0x8e, 0xed, @@ -2571,7 +2570,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_12 = RLPItem::String( + let string_12 = RLPItem::String( array![ 0x79, 0x23, @@ -2608,7 +2607,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_13 = RLPItem::String( + let string_13 = RLPItem::String( array![ 0x65, 0x34, @@ -2645,7 +2644,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_14 = RLPItem::String( + let string_14 = RLPItem::String( array![ 0xbf, 0xf9, @@ -2682,7 +2681,7 @@ fn test_rlp_encode_long_list() { ] .span() ); - let mut string_15 = RLPItem::String( + let string_15 = RLPItem::String( array![ 0x7f, 0x14, @@ -2720,9 +2719,9 @@ fn test_rlp_encode_long_list() { .span() ); - let mut string_16 = RLPItem::String(array![].span()); + let string_16 = RLPItem::String(array![].span()); - let mut strings_list = array![ + let strings_list = array![ string_0, string_1, string_2, @@ -2746,7 +2745,7 @@ fn test_rlp_encode_long_list() { let res = RLPTrait::encode(array![list].span()).unwrap(); - let mut expected = array![ + let expected = array![ 0xf9, 0x02, 0x11, @@ -3281,5 +3280,5 @@ fn test_rlp_encode_long_list() { 0x80 ]; - assert(res == expected.span(), 'Wrong value'); + assert!(res == expected.span(), "Wrong value"); } diff --git a/src/linalg/src/dot.cairo b/src/linalg/src/dot.cairo index f98b6a6e..b27292ce 100644 --- a/src/linalg/src/dot.cairo +++ b/src/linalg/src/dot.cairo @@ -5,7 +5,7 @@ /// * `xs` - The first sequence of len L. /// * `ys` - The second sequence of len L. /// # Returns -/// * `T` - The dot product. +/// * `sum` - The dot product. fn dot, +AddEq, +Zeroable, +Copy, +Drop,>( mut xs: Span, mut ys: Span ) -> T { @@ -13,14 +13,11 @@ fn dot, +AddEq, +Zeroable, +Copy, +Drop,>( assert(xs.len() == ys.len(), 'Arrays must have the same len'); // [Compute] Dot product in a loop - let mut value = Zeroable::zero(); - loop { - match xs.pop_front() { - Option::Some(x_value) => { - let y_value = ys.pop_front().unwrap(); - value += *x_value * *y_value; - }, - Option::None => { break value; }, - }; - } + let mut sum = Zeroable::zero(); + while !xs.is_empty() { + let x = *xs.pop_front().unwrap(); + let y = *ys.pop_front().unwrap(); + sum += x * y; + }; + sum } diff --git a/src/linalg/src/tests/dot_test.cairo b/src/linalg/src/tests/dot_test.cairo index bb70ef46..e97106a5 100644 --- a/src/linalg/src/tests/dot_test.cairo +++ b/src/linalg/src/tests/dot_test.cairo @@ -3,16 +3,16 @@ use alexandria_linalg::dot::dot; #[test] #[available_gas(2000000)] fn dot_product_test() { - let mut xs: Array = array![3, 5, 7]; - let mut ys = array![11, 13, 17]; - assert(dot(xs.span(), ys.span()) == 217, 'invalid dot product'); + let xs = array![3_u64, 5, 7]; + let ys = array![11, 13, 17]; + assert_eq!(dot(xs.span(), ys.span()), 217, "invalid dot product"); } #[test] #[should_panic(expected: ('Arrays must have the same len',))] #[available_gas(2000000)] fn dot_product_test_check_len() { - let mut xs: Array = array![1]; - let mut ys = array![]; + let xs = array![1_u64]; + let ys = array![]; dot(xs.span(), ys.span()); } diff --git a/src/linalg/src/tests/kron_test.cairo b/src/linalg/src/tests/kron_test.cairo index 35e66e85..5b6d9c8d 100644 --- a/src/linalg/src/tests/kron_test.cairo +++ b/src/linalg/src/tests/kron_test.cairo @@ -3,25 +3,25 @@ use alexandria_linalg::kron::{kron, KronError}; #[test] #[available_gas(2000000)] fn kron_product_test() { - let mut xs: Array = array![1, 10, 100]; - let mut ys = array![5, 6, 7]; + let xs = array![1_u64, 10, 100]; + let ys = array![5, 6, 7]; let zs = kron(xs.span(), ys.span()).unwrap(); - assert(*zs[0] == 5, 'wrong value at index 0'); - assert(*zs[1] == 6, 'wrong value at index 1'); - assert(*zs[2] == 7, 'wrong value at index 2'); - assert(*zs[3] == 50, 'wrong value at index 3'); - assert(*zs[4] == 60, 'wrong value at index 4'); - assert(*zs[5] == 70, 'wrong value at index 5'); - assert(*zs[6] == 500, 'wrong value at index 6'); - assert(*zs[7] == 600, 'wrong value at index 7'); - assert(*zs[8] == 700, 'wrong value at index 8'); + assert_eq!(*zs[0], 5, "wrong value at index 0"); + assert_eq!(*zs[1], 6, "wrong value at index 1"); + assert_eq!(*zs[2], 7, "wrong value at index 2"); + assert_eq!(*zs[3], 50, "wrong value at index 3"); + assert_eq!(*zs[4], 60, "wrong value at index 4"); + assert_eq!(*zs[5], 70, "wrong value at index 5"); + assert_eq!(*zs[6], 500, "wrong value at index 6"); + assert_eq!(*zs[7], 600, "wrong value at index 7"); + assert_eq!(*zs[8], 700, "wrong value at index 8"); } #[test] #[available_gas(2000000)] fn kron_product_test_check_len() { - let mut xs: Array = array![1]; - let mut ys = array![]; + let xs = array![1_u64]; + let ys = array![]; assert( kron(xs.span(), ys.span()) == Result::Err(KronError::UnequalLength), 'Arrays must have the same len' diff --git a/src/linalg/src/tests/norm_test.cairo b/src/linalg/src/tests/norm_test.cairo index ededb666..023ae75d 100644 --- a/src/linalg/src/tests/norm_test.cairo +++ b/src/linalg/src/tests/norm_test.cairo @@ -3,27 +3,27 @@ use alexandria_linalg::norm::norm; #[test] #[available_gas(2000000)] fn norm_test_1() { - let array: Array = array![3, 4]; - assert(norm(array.span(), 2, 10) == 5, 'invalid l2 norm'); + let array = array![3_u128, 4]; + assert_eq!(norm(array.span(), 2, 10), 5, "invalid l2 norm"); } #[test] #[available_gas(2000000)] fn norm_test_2() { - let array: Array = array![3, 4]; - assert(norm(array.span(), 1, 10) == 7, 'invalid l1 norm'); + let array = array![3_u128, 4]; + assert_eq!(norm(array.span(), 1, 10), 7, "invalid l1 norm"); } #[test] #[available_gas(2000000)] fn norm_test_3() { - let array: Array = array![3, 4]; - assert(norm(array.span(), 0, 10) == 2, 'invalid l1 norm'); + let array = array![3_u128, 4]; + assert_eq!(norm(array.span(), 0, 10), 2, "invalid l1 norm"); } #[test] #[available_gas(2000000)] fn norm_test_into() { - let array: Array = array![3, 4]; - assert(norm(array.span(), 2, 10) == 5, 'invalid l2 norm'); + let array = array![3_u32, 4]; + assert_eq!(norm(array.span(), 2, 10), 5, "invalid l2 norm"); } diff --git a/src/math/src/armstrong_number.cairo b/src/math/src/armstrong_number.cairo index 47299ff6..0eae7df5 100644 --- a/src/math/src/armstrong_number.cairo +++ b/src/math/src/armstrong_number.cairo @@ -8,7 +8,7 @@ use super::{count_digits_of_base, pow}; /// * `bool` - A boolean value indicating is Armstrong Number. fn is_armstrong_number(mut num: u128) -> bool { let mut original_num = num; - let mut digits = count_digits_of_base(num, 10); + let digits = count_digits_of_base(num, 10); loop { if num == 0 { break original_num == 0; diff --git a/src/math/src/fast_root.cairo b/src/math/src/fast_root.cairo index 2657a5cd..9d7ba763 100644 --- a/src/math/src/fast_root.cairo +++ b/src/math/src/fast_root.cairo @@ -21,10 +21,7 @@ fn fast_nr_optimize(x: u128, r: u128, iter: usize) -> u128 { let mut x_optim = round_div(x, r); let mut n_iter = 0; - loop { - if n_iter == iter { - break; - } + while n_iter != iter { let x_r_m1 = pow(x_optim, r - 1); x_optim = round_div(((r - 1) * x_optim + round_div(x, x_r_m1)), r); n_iter += 1; @@ -40,7 +37,7 @@ fn fast_nr_optimize(x: u128, r: u128, iter: usize) -> u128 { /// # Returns /// * ` u128 ` - The sqrt of x with rounding (e.g., sqrt(5) = 2.24 -> 2, sqrt(7) = 2.65 -> 3) fn fast_sqrt(x: u128, iter: usize) -> u128 { - return fast_nr_optimize(x, 2, iter); + fast_nr_optimize(x, 2, iter) } /// Calculate the cubic root of x @@ -50,7 +47,7 @@ fn fast_sqrt(x: u128, iter: usize) -> u128 { /// # Returns /// * ` u128 ` - The cubic root of x with rounding (e.g., cbrt(4) = 1.59 -> 2, cbrt(5) = 1.71 -> 2) fn fast_cbrt(x: u128, iter: usize) -> u128 { - return fast_nr_optimize(x, 3, iter); + fast_nr_optimize(x, 3, iter) } /// Calculate the division of a by b with rounding diff --git a/src/math/src/gcd_of_n_numbers.cairo b/src/math/src/gcd_of_n_numbers.cairo index 4e474e05..9362f9cc 100644 --- a/src/math/src/gcd_of_n_numbers.cairo +++ b/src/math/src/gcd_of_n_numbers.cairo @@ -26,13 +26,10 @@ fn gcd(mut n: Span) -> u128 { // # Returns // * `felt252` - The gcd of a and b fn gcd_two_numbers(mut a: u128, mut b: u128) -> u128 { - loop { - if b == 0 { - break a; - } - + while b != 0 { let r = a % b; a = b; b = r; - } + }; + a } diff --git a/src/math/src/is_prime.cairo b/src/math/src/is_prime.cairo index 4a743b21..7e7ab8d3 100644 --- a/src/math/src/is_prime.cairo +++ b/src/math/src/is_prime.cairo @@ -20,21 +20,17 @@ fn is_prime(n: u128, iter: usize) -> bool { } let divider_limit = fast_sqrt(n, iter); - let mut current_dividier = 3; - let mut ans = true; + let mut current_divider = 3; loop { - if current_dividier > divider_limit { - break; + if current_divider > divider_limit { + break true; } - if n % current_dividier == 0 { - ans = false; - break; + if n % current_divider == 0 { + break false; } - current_dividier += 2; - }; - - ans + current_divider += 2; + } } diff --git a/src/math/src/keccak256.cairo b/src/math/src/keccak256.cairo index 3b6e21dc..7788ce96 100644 --- a/src/math/src/keccak256.cairo +++ b/src/math/src/keccak256.cairo @@ -15,7 +15,7 @@ impl U64Impl of U64Trait { assert(self.len() < 9, 'bytes dont fit in u64'); // Pack full value let mut value: u64 = 0; - let mut n_bytes: u32 = self.len(); + let n_bytes: u32 = self.len(); loop { let byte = match self.pop_back() { Option::Some(byte) => *byte, @@ -46,18 +46,14 @@ fn reverse_endianness(value: u256) -> u256 { fn keccak256(mut self: Span) -> u256 { // Converts byte array to little endian 8 byte words array. let mut words64: Array = Default::default(); - let (last_word, last_word_bytes) = loop { - // Specifically handle last word - if self.len() < 8 { - let (value, n_bytes) = U64Trait::from_le_bytes(self); - break (value, n_bytes); - }; - let mut current_word = self.slice(0, 8); + while self.len() >= 8 { + let current_word = self.slice(0, 8); let (value, _) = U64Trait::from_le_bytes(current_word); words64.append(value); self = self.slice(8, self.len() - 8); }; - let mut hash = reverse_endianness(cairo_keccak(ref words64, last_word, last_word_bytes)); - hash + // handle last word specifically + let (last_word, last_word_bytes) = U64Trait::from_le_bytes(self); + reverse_endianness(cairo_keccak(ref words64, last_word, last_word_bytes)) } diff --git a/src/math/src/lcm_of_n_numbers.cairo b/src/math/src/lcm_of_n_numbers.cairo index 0cbc02b6..a76177fa 100644 --- a/src/math/src/lcm_of_n_numbers.cairo +++ b/src/math/src/lcm_of_n_numbers.cairo @@ -1,8 +1,5 @@ //! # LCM for N numbers use alexandria_math::gcd_of_n_numbers::gcd_two_numbers; -use core::option::OptionTrait; -use core::traits::Into; -use core::traits::TryInto; #[derive(Drop, Copy, PartialEq)] enum LCMError { diff --git a/src/math/src/tests/aliquot_sum_test.cairo b/src/math/src/tests/aliquot_sum_test.cairo index a74bdf5e..9ff5da22 100644 --- a/src/math/src/tests/aliquot_sum_test.cairo +++ b/src/math/src/tests/aliquot_sum_test.cairo @@ -3,34 +3,34 @@ use alexandria_math::aliquot_sum::aliquot_sum; #[test] #[available_gas(200000)] fn zero_test() { - assert(aliquot_sum(0) == 0, 'invalid result'); + assert!(aliquot_sum(0) == 0, "invalid result"); } #[test] #[available_gas(200000)] fn one_test() { - assert(aliquot_sum(1) == 0, 'invalid result'); + assert!(aliquot_sum(1) == 0, "invalid result"); } #[test] #[available_gas(200000)] fn one_digit_number_test() { - assert(aliquot_sum(6) == 6, 'invalid result'); + assert!(aliquot_sum(6) == 6, "invalid result"); } #[test] #[available_gas(2000000)] fn two_digit_number_test() { - assert(aliquot_sum(15) == 9, 'invalid result'); + assert!(aliquot_sum(15) == 9, "invalid result"); } #[test] #[available_gas(20000000)] fn three_digit_number_test() { - assert(aliquot_sum(343) == 57, 'invalid result'); + assert!(aliquot_sum(343) == 57, "invalid result"); } #[test] #[available_gas(2000000)] fn two_digit_prime_number_test() { - assert(aliquot_sum(17) == 1, 'invalid result'); + assert!(aliquot_sum(17) == 1, "invalid result"); } diff --git a/src/math/src/tests/armstrong_number_test.cairo b/src/math/src/tests/armstrong_number_test.cairo index e624fedd..d40e6c7f 100644 --- a/src/math/src/tests/armstrong_number_test.cairo +++ b/src/math/src/tests/armstrong_number_test.cairo @@ -3,23 +3,23 @@ use alexandria_math::armstrong_number::is_armstrong_number; #[test] #[available_gas(200000)] fn one_digit_armstrong_number_test() { - assert(is_armstrong_number(1), 'invalid result'); + assert!(is_armstrong_number(1), "invalid result"); } #[test] #[available_gas(200000)] fn two_digit_numbers_are_not_armstrong_numbers_test() { - assert(!is_armstrong_number(15), 'invalid result'); + assert!(!is_armstrong_number(15), "invalid result"); } #[test] #[available_gas(2000000)] fn three_digit_armstrong_number_test() { - assert(is_armstrong_number(153), 'invalid result'); + assert!(is_armstrong_number(153), "invalid result"); } #[test] #[available_gas(2000000)] fn three_digit_non_armstrong_number_test() { - assert(!is_armstrong_number(105), 'invalid result'); + assert!(!is_armstrong_number(105), "invalid result"); } diff --git a/src/math/src/tests/collatz_sequence_test.cairo b/src/math/src/tests/collatz_sequence_test.cairo index 0884ae1b..6a8a28d7 100644 --- a/src/math/src/tests/collatz_sequence_test.cairo +++ b/src/math/src/tests/collatz_sequence_test.cairo @@ -3,17 +3,17 @@ use alexandria_math::collatz_sequence::sequence; #[test] #[available_gas(2000000)] fn collatz_sequence_10_test() { - assert(sequence(10).len() == 7, 'invalid result'); + assert_eq!(sequence(10).len(), 7, "invalid result"); } #[test] #[available_gas(2000000)] fn collatz_sequence_15_test() { - assert(sequence(15).len() == 18, 'invalid result'); + assert_eq!(sequence(15).len(), 18, "invalid result"); } #[test] #[available_gas(2000000)] fn collatz_sequence_empty_test() { - assert(sequence(0).len() == 0, 'invalid result'); + assert_eq!(sequence(0).len(), 0, "invalid result"); } diff --git a/src/math/src/tests/ed25519_test.cairo b/src/math/src/tests/ed25519_test.cairo index 190a3f6c..22fb2789 100644 --- a/src/math/src/tests/ed25519_test.cairo +++ b/src/math/src/tests/ed25519_test.cairo @@ -130,7 +130,7 @@ fn verify_signature_test() { let sig: Span = gen_sig(); let pub_key: Span = gen_pub_key(); - assert(verify_signature(msg, sig, pub_key), 'Invalid signature'); + assert!(verify_signature(msg, sig, pub_key), "Invalid signature"); } #[test] @@ -140,7 +140,7 @@ fn verify_wrong_signature_test() { let sig: Span = gen_sig(); let pub_key: Span = gen_pub_key(); - assert(!verify_signature(wrong_msg, sig, pub_key), 'Signature should be invalid'); + assert!(!verify_signature(wrong_msg, sig, pub_key), "Signature should be invalid"); } #[test] @@ -150,7 +150,7 @@ fn verify_signature_empty_sig_test() { let sig = array![].span(); let pub_key: Span = gen_pub_key(); - assert(!verify_signature(empty_msg, sig, pub_key), 'Signature should be invalid'); + assert!(!verify_signature(empty_msg, sig, pub_key), "Signature should be invalid"); } #[test] @@ -160,5 +160,5 @@ fn verify_signature_empty_pub_key_test() { let sig: Span = gen_sig(); let pub_key = array![].span(); - assert(!verify_signature(empty_msg, sig, pub_key), 'Signature should be invalid'); + assert!(!verify_signature(empty_msg, sig, pub_key), "Signature should be invalid"); } diff --git a/src/math/src/tests/extended_euclidean_algorithm_test.cairo b/src/math/src/tests/extended_euclidean_algorithm_test.cairo index 9981240f..17428bc6 100644 --- a/src/math/src/tests/extended_euclidean_algorithm_test.cairo +++ b/src/math/src/tests/extended_euclidean_algorithm_test.cairo @@ -6,10 +6,10 @@ use alexandria_math::extended_euclidean_algorithm::{ fn test_case(a: u128, b: u128, expected: (u128, u128, u128)) { let (gcd, x, y) = extended_euclidean_algorithm(a, b); let (expected_gcd, expected_x, expected_y) = expected; - assert(gcd == expected_gcd, 'gcd is incorrect'); + assert!(gcd == expected_gcd, "gcd is incorrect"); - assert(x == expected_x, 'x is incorrect'); - assert(y == expected_y, 'y is incorrect'); + assert!(x == expected_x, "x is incorrect"); + assert!(y == expected_y, "y is incorrect"); } #[test] diff --git a/src/math/src/tests/fast_power_test.cairo b/src/math/src/tests/fast_power_test.cairo index 513db00d..83230017 100644 --- a/src/math/src/tests/fast_power_test.cairo +++ b/src/math/src/tests/fast_power_test.cairo @@ -3,20 +3,20 @@ use alexandria_math::fast_power::fast_power; #[test] #[available_gas(1000000000)] fn fast_power_test() { - assert(fast_power(2, 1, 17) == 2, 'invalid result'); - assert(fast_power(2, 2, 17) == 4, 'invalid result'); - assert(fast_power(2, 3, 17) == 8, 'invalid result'); - assert(fast_power(3, 4, 17) == 13, 'invalid result'); - assert(fast_power(2, 100, 1000000007) == 976371285, 'invalid result'); + assert_eq!(fast_power(2, 1, 17), 2, "invalid result"); + assert_eq!(fast_power(2, 2, 17), 4, "invalid result"); + assert_eq!(fast_power(2, 3, 17), 8, "invalid result"); + assert_eq!(fast_power(3, 4, 17), 13, "invalid result"); + assert_eq!(fast_power(2, 100, 1000000007), 976371285, "invalid result"); assert( fast_power( 2, 127, 340282366920938463463374607431768211454 ) == 170141183460469231731687303715884105728, 'invalid result' ); - assert(fast_power(2, 127, 34028236692093846346337460743176821144) == 8, 'invalid result'); + assert_eq!(fast_power(2, 127, 34028236692093846346337460743176821144), 8, "invalid result"); - assert(fast_power(2, 128, 9299) == 1412, 'invalid result'); + assert_eq!(fast_power(2, 128, 9299), 1412, "invalid result"); assert( fast_power(2, 88329, 34028236692093846346337460743176821144) == 2199023255552, diff --git a/src/math/src/tests/fast_root_test.cairo b/src/math/src/tests/fast_root_test.cairo index b57fd78f..565206f5 100644 --- a/src/math/src/tests/fast_root_test.cairo +++ b/src/math/src/tests/fast_root_test.cairo @@ -5,29 +5,29 @@ use alexandria_math::fast_root::fast_sqrt; #[test] #[available_gas(5000000)] fn fast_sqrt_test_1() { - assert(fast_sqrt(100, 10) == 10, 'invalid result'); + assert_eq!(fast_sqrt(100, 10), 10, "invalid result"); } #[test] #[available_gas(5000000)] fn fast_sqrt_test_2() { - assert(fast_sqrt(79, 10) == 9, 'invalid result'); + assert_eq!(fast_sqrt(79, 10), 9, "invalid result"); } #[test] #[available_gas(5000000)] fn fast_curt_test_1() { - assert(fast_cbrt(1000, 10) == 10, 'invalid result'); + assert_eq!(fast_cbrt(1000, 10), 10, "invalid result"); } #[test] #[available_gas(5000000)] fn fast_nr_optimize_test_1() { - assert(fast_nr_optimize(10000, 4, 30) == 10, 'invalid result'); + assert_eq!(fast_nr_optimize(10000, 4, 30), 10, "invalid result"); } #[test] #[available_gas(5000000)] fn fast_nr_optimize_test_2() { - assert(fast_nr_optimize(10, 1, 10) == 10, 'invalid result'); + assert_eq!(fast_nr_optimize(10, 1, 10), 10, "invalid result"); } diff --git a/src/math/src/tests/fibonacci_test.cairo b/src/math/src/tests/fibonacci_test.cairo index e72283cd..79effb3d 100644 --- a/src/math/src/tests/fibonacci_test.cairo +++ b/src/math/src/tests/fibonacci_test.cairo @@ -3,6 +3,6 @@ use alexandria_math::fibonacci::fib; #[test] #[available_gas(200000)] fn fibonacci_test() { - assert(fib(0, 1, 10) == 55, 'invalid result'); - assert(fib(2, 4, 8) == 110, 'invalid result'); + assert!(fib(0, 1, 10) == 55, "invalid result"); + assert!(fib(2, 4, 8) == 110, "invalid result"); } diff --git a/src/math/src/tests/gcd_of_n_numbers_test.cairo b/src/math/src/tests/gcd_of_n_numbers_test.cairo index 97f0ce46..c928deef 100644 --- a/src/math/src/tests/gcd_of_n_numbers_test.cairo +++ b/src/math/src/tests/gcd_of_n_numbers_test.cairo @@ -4,21 +4,21 @@ use alexandria_math::gcd_of_n_numbers::gcd; #[available_gas(1000000000)] fn gcd_test() { let arr = array![2, 4, 6, 8, 10]; - assert(gcd(arr.span()) == 2, 'invalid result'); + assert_eq!(gcd(arr.span()), 2, "invalid result"); } #[test] #[available_gas(1000000000)] fn gcd_test_inverse() { let arr = array![10, 8, 6, 4, 2]; - assert(gcd(arr.span()) == 2, 'invalid result'); + assert_eq!(gcd(arr.span()), 2, "invalid result"); } #[test] #[available_gas(1000000000)] fn gcd_test_3() { let arr = array![3, 6, 12, 99]; - assert(gcd(arr.span()) == 3, 'invalid result'); + assert_eq!(gcd(arr.span()), 3, "invalid result"); } @@ -26,7 +26,7 @@ fn gcd_test_3() { #[available_gas(1000000000)] fn gcd_single_test() { let arr = array![10]; - assert(gcd(arr.span()) == 10, 'invalid result'); + assert_eq!(gcd(arr.span()), 10, "invalid result"); } #[test] diff --git a/src/math/src/tests/i257_test.cairo b/src/math/src/tests/i257_test.cairo index 454c58d9..f2a6aa4f 100644 --- a/src/math/src/tests/i257_test.cairo +++ b/src/math/src/tests/i257_test.cairo @@ -6,36 +6,36 @@ fn i257_test_add() { let a = i257 { abs: 42, is_negative: false }; let b = i257 { abs: 13, is_negative: false }; let result = a + b; - assert(result.abs == 55, '42 + 13 = 55'); - assert(!result.is_negative, '42 + 13 -> positive'); + assert_eq!(result.abs, 55, "42 + 13 = 55"); + assert!(!result.is_negative, "42 + 13 -> positive"); // Test addition of two negative integers let a = i257 { abs: 42, is_negative: true }; let b = i257 { abs: 13, is_negative: true }; let result = a + b; - assert(result.abs == 55, '-42 - 13 = -55'); - assert(result.is_negative, '-42 - 13 -> negative'); + assert_eq!(result.abs, 55, "-42 - 13 = -55"); + assert!(result.is_negative, "-42 - 13 -> negative"); // Test addition of a positive integer and a negative integer with the same magnitude let a = i257 { abs: 42, is_negative: false }; let b = i257 { abs: 42, is_negative: true }; let result = a + b; - assert(result.abs == 0, '42 - 42 = 0'); - assert(!result.is_negative, '42 - 42 -> positive'); + assert_eq!(result.abs, 0, "42 - 42 = 0"); + assert!(!result.is_negative, "42 - 42 -> positive"); // Test addition of a positive integer and a negative integer with different magnitudes let a = i257 { abs: 42, is_negative: false }; let b = i257 { abs: 13, is_negative: true }; let result = a + b; - assert(result.abs == 29, '42 - 13 = 29'); - assert(!result.is_negative, '42 - 13 -> positive'); + assert_eq!(result.abs, 29, "42 - 13 = 29"); + assert!(!result.is_negative, "42 - 13 -> positive"); // Test addition of a negative integer and a positive integer with different magnitudes let a = i257 { abs: 42, is_negative: true }; let b = i257 { abs: 13, is_negative: false }; let result = a + b; - assert(result.abs == 29, '-42 + 13 = -29'); - assert(result.is_negative, '-42 + 13 -> negative'); + assert_eq!(result.abs, 29, "-42 + 13 = -29"); + assert!(result.is_negative, "-42 + 13 -> negative"); } #[test] @@ -44,64 +44,64 @@ fn i257_test_sub() { let a = i257 { abs: 42, is_negative: false }; let b = i257 { abs: 13, is_negative: false }; let result = a - b; - assert(result.abs == 29, '42 - 13 = 29'); - assert(!result.is_negative, '42 - 13 -> positive'); + assert_eq!(result.abs, 29, "42 - 13 = 29"); + assert!(!result.is_negative, "42 - 13 -> positive"); // Test subtraction of two positive integers with larger second let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 42, is_negative: false }; let result = a - b; - assert(result.abs == 29, '13 - 42 = -29'); - assert(result.is_negative, '13 - 42 -> negative'); + assert_eq!(result.abs, 29, "13 - 42 = -29"); + assert!(result.is_negative, "13 - 42 -> negative"); // Test subtraction of two negative integers with larger first let a = i257 { abs: 42, is_negative: true }; let b = i257 { abs: 13, is_negative: true }; let result = a - b; - assert(result.abs == 29, '-42 - -13 = 29'); - assert(result.is_negative, '-42 - -13 -> negative'); + assert_eq!(result.abs, 29, "-42 - -13 = 29"); + assert!(result.is_negative, "-42 - -13 -> negative"); // Test subtraction of two negative integers with larger second let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 42, is_negative: true }; let result = a - b; - assert(result.abs == 29, '-13 - -42 = 29'); - assert(!result.is_negative, '-13 - -42 -> positive'); + assert_eq!(result.abs, 29, "-13 - -42 = 29"); + assert!(!result.is_negative, "-13 - -42 -> positive"); // Test subtraction of a positive integer and a negative integer with the same magnitude let a = i257 { abs: 42, is_negative: false }; let b = i257 { abs: 42, is_negative: true }; let result = a - b; - assert(result.abs == 84, '42 - -42 = 84'); - assert(!result.is_negative, '42 - -42 -> postive'); + assert_eq!(result.abs, 84, "42 - -42 = 84"); + assert!(!result.is_negative, "42 - -42 -> postive"); // Test subtraction of a negative integer and a positive integer with the same magnitude let a = i257 { abs: 42, is_negative: true }; let b = i257 { abs: 42, is_negative: false }; let result = a - b; - assert(result.abs == 84, '-42 - 42 = -84'); - assert(result.is_negative, '-42 - 42 -> negative'); + assert_eq!(result.abs, 84, "-42 - 42 = -84"); + assert!(result.is_negative, "-42 - 42 -> negative"); // Test subtraction of a positive integer and a negative integer with different magnitudes let a = i257 { abs: 100, is_negative: false }; let b = i257 { abs: 42, is_negative: true }; let result = a - b; - assert(result.abs == 142, '100 - - 42 = 142'); - assert(!result.is_negative, '100 - - 42 -> postive'); + assert_eq!(result.abs, 142, "100 - - 42 = 142"); + assert!(!result.is_negative, "100 - - 42 -> postive"); // Test subtraction of a negative integer and a positive integer with different magnitudes let a = i257 { abs: 42, is_negative: true }; let b = i257 { abs: 100, is_negative: false }; let result = a - b; - assert(result.abs == 142, '-42 - 100 = -142'); - assert(result.is_negative, '-42 - 100 -> negative'); + assert_eq!(result.abs, 142, "-42 - 100 = -142"); + assert!(result.is_negative, "-42 - 100 -> negative"); // Test subtraction resulting in zero let a = i257 { abs: 42, is_negative: false }; let b = i257 { abs: 42, is_negative: false }; let result = a - b; - assert(result.abs == 0, '42 - 42 = 0'); - assert(!result.is_negative, '42 - 42 -> positive'); + assert_eq!(result.abs, 0, "42 - 42 = 0"); + assert!(!result.is_negative, "42 - 42 -> positive"); } @@ -111,29 +111,29 @@ fn i257_test_mul() { let a = i257 { abs: 10, is_negative: false }; let b = i257 { abs: 5, is_negative: false }; let result = a * b; - assert(result.abs == 50, '10 * 5 = 50'); - assert(!result.is_negative, '10 * 5 -> positive'); + assert_eq!(result.abs, 50, "10 * 5 = 50"); + assert!(!result.is_negative, "10 * 5 -> positive"); // Test multiplication of negative integers let a = i257 { abs: 10, is_negative: true }; let b = i257 { abs: 5, is_negative: true }; let result = a * b; - assert(result.abs == 50, '-10 * -5 = 50'); - assert(!result.is_negative, '-10 * -5 -> positive'); + assert_eq!(result.abs, 50, "-10 * -5 = 50"); + assert!(!result.is_negative, "-10 * -5 -> positive"); // Test multiplication of positive and negative integers let a = i257 { abs: 10, is_negative: false }; let b = i257 { abs: 5, is_negative: true }; let result = a * b; - assert(result.abs == 50, '10 * -5 = -50'); - assert(result.is_negative, '10 * -5 -> negative'); + assert_eq!(result.abs, 50, "10 * -5 = -50"); + assert!(result.is_negative, "10 * -5 -> negative"); // Test multiplication by zero let a = i257 { abs: 10, is_negative: false }; let b = i257 { abs: 0, is_negative: false }; let result = a * b; - assert(result.abs == 0, '10 * 0 = 0'); - assert(!result.is_negative, '10 * 0 -> positive'); + assert_eq!(result.abs, 0, "10 * 0 = 0"); + assert!(!result.is_negative, "10 * 0 -> positive"); } #[test] @@ -142,36 +142,36 @@ fn i257_test_div_no_rem() { let a = i257 { abs: 10, is_negative: false }; let b = i257 { abs: 5, is_negative: false }; let result = a / b; - assert(result.abs == 2, '10 // 5 = 2'); - assert(!result.is_negative, '10 // 5 -> positive'); + assert_eq!(result.abs, 2, "10 // 5 = 2"); + assert!(!result.is_negative, "10 // 5 -> positive"); // Test division of negative integers let a = i257 { abs: 10, is_negative: true }; let b = i257 { abs: 5, is_negative: true }; let result = a / b; - assert(result.abs == 2, '-10 // -5 = 2'); - assert(!result.is_negative, '-10 // -5 -> positive'); + assert_eq!(result.abs, 2, "-10 // -5 = 2"); + assert!(!result.is_negative, "-10 // -5 -> positive"); // Test division of positive and negative integers let a = i257 { abs: 10, is_negative: false }; let b = i257 { abs: 5, is_negative: true }; let result = a / b; - assert(result.abs == 2, '10 // -5 = -2'); - assert(result.is_negative, '10 // -5 -> negative'); + assert_eq!(result.abs, 2, "10 // -5 = -2"); + assert!(result.is_negative, "10 // -5 -> negative"); // Test division with a = zero let a = i257 { abs: 0, is_negative: false }; let b = i257 { abs: 10, is_negative: false }; let result = a / b; - assert(result.abs == 0, '0 // 10 = 0'); - assert(!result.is_negative, '0 // 10 -> positive'); + assert_eq!(result.abs, 0, "0 // 10 = 0"); + assert!(!result.is_negative, "0 // 10 -> positive"); // Test division with a = zero let a = i257 { abs: 0, is_negative: false }; let b = i257 { abs: 10, is_negative: false }; let result = a / b; - assert(result.abs == 0, '0 // 10 = 0'); - assert(!result.is_negative, '0 // 10 -> positive'); + assert_eq!(result.abs, 0, "0 // 10 = 0"); + assert!(!result.is_negative, "0 // 10 -> positive"); } #[test] @@ -180,36 +180,36 @@ fn i257_test_div_rem() { let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 5, is_negative: false }; let (q, r) = i257_div_rem(a, b); - assert(q.abs == 2 && r.abs == 3, '13 // 5 = 2 r 3'); - assert(!q.is_negative && !r.is_negative, '13 // 5 -> positive'); + assert!(q.abs == 2 && r.abs == 3, "13 // 5 = 2 r 3"); + assert!(!q.is_negative && !r.is_negative, "13 // 5 -> positive"); // Test division and remainder of negative integers let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 5, is_negative: true }; let (q, r) = i257_div_rem(a, b); - assert(q.abs == 2 && r.abs == 3, '-13 // -5 = 2 r -3'); - assert(!q.is_negative && r.is_negative, '-13 // -5 -> positive'); + assert!(q.abs == 2 && r.abs == 3, "-13 // -5 = 2 r -3"); + assert!(!q.is_negative && r.is_negative, "-13 // -5 -> positive"); // Test division and remainder of positive and negative integers let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 5, is_negative: true }; let (q, r) = i257_div_rem(a, b); - assert(q.abs == 3 && r.abs == 2, '13 // -5 = -3 r -2'); - assert(q.is_negative && r.is_negative, '13 // -5 -> negative'); + assert!(q.abs == 3 && r.abs == 2, "13 // -5 = -3 r -2"); + assert!(q.is_negative && r.is_negative, "13 // -5 -> negative"); // Test division with a = zero let a = i257 { abs: 0, is_negative: false }; let b = i257 { abs: 10, is_negative: false }; let (q, r) = i257_div_rem(a, b); - assert(q.abs == 0 && r.abs == 0, '0 // 10 = 0 r 0'); - assert(!q.is_negative && !r.is_negative, '0 // 10 -> positive'); + assert!(q.abs == 0 && r.abs == 0, "0 // 10 = 0 r 0"); + assert!(!q.is_negative && !r.is_negative, "0 // 10 -> positive"); // Test division and remainder with a negative dividend and positive divisor let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 5, is_negative: false }; let (q, r) = i257_div_rem(a, b); - assert(q.abs == 3 && r.abs == 2, '-13 // 5 = -3 r 2'); - assert(q.is_negative && !r.is_negative, '-13 // 5 -> negative'); + assert!(q.abs == 3 && r.abs == 2, "-13 // 5 = -3 r 2"); + assert!(q.is_negative && !r.is_negative, "-13 // 5 -> negative"); } #[test] @@ -217,34 +217,34 @@ fn i257_test_partial_ord() { // Test two postive integers let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 5, is_negative: false }; - assert(a > b, '13 > 5'); - assert(a >= b, '13 >= 5'); - assert(b < a, '5 < 13'); - assert(b <= a, '5 <= 13'); + assert!(a > b, "13 > 5"); + assert!(a >= b, "13 >= 5"); + assert!(b < a, "5 < 13"); + assert!(b <= a, "5 <= 13"); // Test `a` postive and `b` negative let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 5, is_negative: true }; - assert(a > b, '13 > -5'); - assert(a >= b, '13 >= -5'); - assert(b < a, '-5 < 13'); - assert(b <= a, '-5 <= 13'); + assert!(a > b, "13 > -5"); + assert!(a >= b, "13 >= -5"); + assert!(b < a, "-5 < 13"); + assert!(b <= a, "-5 <= 13"); // Test `a` negative and `b` postive let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 5, is_negative: false }; - assert(b > a, '5 > -13'); - assert(b >= a, '5 >= -13'); - assert(a < b, '-13 < 5'); - assert(a <= b, '5 <= -13'); + assert!(b > a, "5 > -13"); + assert!(b >= a, "5 >= -13"); + assert!(a < b, "-13 < 5"); + assert!(a <= b, "5 <= -13"); // Test `a` negative and `b` negative let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 5, is_negative: true }; - assert(b > a, '-5 > -13'); - assert(b >= a, '-13 >= -5'); - assert(a < b, '-13 < -5'); - assert(a <= b, '-13 <= -5'); + assert!(b > a, "-5 > -13"); + assert!(b >= a, "-13 >= -5"); + assert!(a < b, "-13 < -5"); + assert!(a <= b, "-13 <= -5"); } #[test] @@ -252,22 +252,22 @@ fn i257_test_eq_not_eq() { // Test two postive integers let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 5, is_negative: false }; - assert(a != b, '13 != 5'); + assert!(a != b, "13 != 5"); // Test `a` postive and `b` negative let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 5, is_negative: true }; - assert(a != b, '13 != -5'); + assert!(a != b, "13 != -5"); // Test `a` negative and `b` postive let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 5, is_negative: false }; - assert(a != b, '-13 != 5'); + assert!(a != b, "-13 != 5"); // Test `a` negative and `b` negative let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 5, is_negative: true }; - assert(a != b, '-13 != -5'); + assert!(a != b, "-13 != -5"); } #[test] @@ -275,32 +275,32 @@ fn i257_test_equality() { // Test equal with two positive integers let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 13, is_negative: false }; - assert(a == b, '13 == 13'); + assert!(a == b, "13 == 13"); // Test equal with two negative integers let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 13, is_negative: true }; - assert(a == b, '-13 == -13'); + assert!(a == b, "-13 == -13"); // Test not equal with two postive integers let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 5, is_negative: false }; - assert(a != b, '13 != 5'); + assert!(a != b, "13 != 5"); // Test not equal with `a` postive and `b` negative let a = i257 { abs: 13, is_negative: false }; let b = i257 { abs: 5, is_negative: true }; - assert(a != b, '13 != -5'); + assert!(a != b, "13 != -5"); // Test not equal with `a` negative and `b` postive let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 5, is_negative: false }; - assert(a != b, '-13 != 5'); + assert!(a != b, "-13 != 5"); // Test not equal with `a` negative and `b` negative let a = i257 { abs: 13, is_negative: true }; let b = i257 { abs: 5, is_negative: true }; - assert(a != b, '-13 != -5'); + assert!(a != b, "-13 != -5"); } #[test] @@ -313,17 +313,17 @@ fn i257_test_check_sign_zero() { #[test] fn i257_test_div_sign_zero() { let x = i257 { abs: 0, is_negative: false } / i257 { abs: 3, is_negative: true }; - assert(x.abs == 0, 'incorrect abs'); - assert(!x.is_negative, 'incorrect sign'); + assert_eq!(x.abs, 0, "incorrect abs"); + assert!(!x.is_negative, "incorrect sign"); } #[test] fn i257_test_into() { let x: i257 = 35.into(); - assert(x.abs == 35, 'incorrect into value'); - assert(!x.is_negative, 'incorrect into sign'); + assert_eq!(x.abs, 35, "incorrect into value"); + assert!(!x.is_negative, "incorrect into sign"); let y: i257 = 258973.into(); - assert(y.abs == 258973, 'incorrect into value'); - assert(!y.is_negative, 'incorrect into sign'); + assert_eq!(y.abs, 258973, "incorrect into value"); + assert!(!y.is_negative, "incorrect into sign"); } diff --git a/src/math/src/tests/is_power_of_two_test.cairo b/src/math/src/tests/is_power_of_two_test.cairo index 1040726e..117460c9 100644 --- a/src/math/src/tests/is_power_of_two_test.cairo +++ b/src/math/src/tests/is_power_of_two_test.cairo @@ -3,29 +3,29 @@ use alexandria_math::is_power_of_two::is_power_of_two; #[test] #[available_gas(200000)] fn is_power_of_two_test_1() { - assert(is_power_of_two(1) == true, 'invalid result'); + assert!(is_power_of_two(1), "invalid result"); } #[test] #[available_gas(200000)] fn is_power_of_two_test_2() { - assert(is_power_of_two(2) == true, 'invalid result'); + assert!(is_power_of_two(2), "invalid result"); } #[test] #[available_gas(200000)] fn is_power_of_two_test_3() { - assert(is_power_of_two(3) == false, 'invalid result'); + assert!(!is_power_of_two(3), "invalid result"); } #[test] #[available_gas(200000)] fn is_power_of_two_test_4() { - assert(is_power_of_two(128) == true, 'invalid result'); + assert!(is_power_of_two(128), "invalid result"); } #[test] #[available_gas(200000)] fn is_power_of_two_test_5() { - assert(is_power_of_two(0) == false, 'invalid result'); + assert!(is_power_of_two(0) == false, "invalid result"); } diff --git a/src/math/src/tests/is_prime_test.cairo b/src/math/src/tests/is_prime_test.cairo index 7f2c3efe..64bcee0e 100644 --- a/src/math/src/tests/is_prime_test.cairo +++ b/src/math/src/tests/is_prime_test.cairo @@ -3,23 +3,23 @@ use alexandria_math::is_prime::is_prime; #[test] #[available_gas(200000)] fn is_prime_test_1() { - assert(is_prime(2, 10), 'invalid result'); + assert!(is_prime(2, 10), "invalid result"); } #[test] #[available_gas(200000)] fn is_prime_test_2() { - assert(!is_prime(0, 10), 'invalid result'); + assert!(!is_prime(0, 10), "invalid result"); } #[test] #[available_gas(200000)] fn is_prime_test_3() { - assert(!is_prime(1, 10), 'invalid result'); + assert!(!is_prime(1, 10), "invalid result"); } #[test] #[available_gas(2000000)] fn is_prime_test_4() { - assert(is_prime(97, 10), 'invalid result'); + assert!(is_prime(97, 10), "invalid result"); } diff --git a/src/math/src/tests/karatsuba_test.cairo b/src/math/src/tests/karatsuba_test.cairo index d38aa9e2..6bd3b69b 100644 --- a/src/math/src/tests/karatsuba_test.cairo +++ b/src/math/src/tests/karatsuba_test.cairo @@ -8,7 +8,7 @@ fn multiply_same_size_positive_number() { let n1 = 31415; let n2 = 31415; let result = 986902225; - assert(multiply(n1, n2) == result, 'invalid result'); + assert_eq!(multiply(n1, n2), result, "invalid result"); } @@ -18,7 +18,7 @@ fn multiply_distinct_size_positive_number() { let n1 = 10296; let n2 = 25912511; let result = 266795213256; - assert(multiply(n1, n2) == result, 'invalid result'); + assert_eq!(multiply(n1, n2), result, "invalid result"); } #[test] @@ -28,7 +28,7 @@ fn multiply_by_zero() { let n1 = 10296; let n2 = 0; let result = 0; - assert(multiply(n1, n2) == result, 'invalid result'); + assert_eq!(multiply(n1, n2), result, "invalid result"); } #[test] @@ -37,5 +37,5 @@ fn multiply_by_number_lt_ten() { let n1 = 1000; let n2 = 2; let result = 2000; - assert(multiply(n1, n2) == result, 'invalid result'); + assert_eq!(multiply(n1, n2), result, "invalid result"); } diff --git a/src/math/src/tests/lcm_of_n_numbers_test.cairo b/src/math/src/tests/lcm_of_n_numbers_test.cairo index 1f51879a..18ef27b0 100644 --- a/src/math/src/tests/lcm_of_n_numbers_test.cairo +++ b/src/math/src/tests/lcm_of_n_numbers_test.cairo @@ -1,9 +1,9 @@ use alexandria_math::lcm_of_n_numbers::{lcm, LCMError}; -use core::traits::Into; // the following trait is not safe, it is only used for testing. -impl u128_to_u32 of Into { +impl u128_into_u32 of Into { fn into(self: u128) -> u32 { + let self: felt252 = self.into(); self.try_into().unwrap() } } @@ -11,36 +11,36 @@ impl u128_to_u32 of Into { #[test] #[available_gas(1000000000)] fn lcm_test() { - let arr = array![2_u128, 4_u128, 6_u128, 8_u128, 10_u128]; - assert(lcm(arr.span()).unwrap() == 120, 'invalid result'); + let arr = array![2_u128, 4, 6, 8, 10]; + assert_eq!(lcm(arr.span()).unwrap(), 120, "invalid result"); } #[test] #[available_gas(1000000000)] fn lcm_test_tryinto() { - let arr = array![2_u32, 4_u32, 6_u32, 8_u32, 10_u32]; - assert(lcm(arr.span()).unwrap() == 120, 'invalid result'); + let arr = array![2_u32, 4, 6, 8, 10]; + assert_eq!(lcm(arr.span()).unwrap(), 120, "invalid result"); } #[test] #[available_gas(1000000000)] fn lcm_test_inverse() { - let arr = array![10_u128, 8_u128, 6_u128, 4_u128, 2_u128]; - assert(lcm(arr.span()).unwrap() == 120, 'invalid result'); + let arr = array![10_u128, 8, 6, 4, 2]; + assert_eq!(lcm(arr.span()).unwrap(), 120, "invalid result"); } #[test] #[available_gas(1000000000)] fn lcm_test_3() { - let arr = array![3_u128, 6_u128, 12_u128, 99_u128]; - assert(lcm(arr.span()).unwrap() == 396, 'invalid result'); + let arr = array![3_u128, 6, 12, 99]; + assert_eq!(lcm(arr.span()).unwrap(), 396, "invalid result"); } #[test] #[available_gas(1000000000)] fn lcm_test_4() { - let arr = array![1_u128, 2_u128, 8_u128, 3_u128]; - assert(lcm(arr.span()).unwrap() == 24, 'invalid result'); + let arr = array![1_u128, 2, 8, 3]; + assert_eq!(lcm(arr.span()).unwrap(), 24, "invalid result"); } @@ -48,12 +48,12 @@ fn lcm_test_4() { #[available_gas(1000000000)] fn lcm_single_test() { let arr = array![10_u128]; - assert(lcm(arr.span()).unwrap() == 10, 'invalid result'); + assert_eq!(lcm(arr.span()).unwrap(), 10, "invalid result"); } #[test] #[available_gas(1000000000)] fn lcm_empty_input_test() { - let mut arr: Array = array![]; - assert(lcm(arr.span()) == Result::Err(LCMError::EmptyInput), 'Empty inputs'); + let arr: Array = array![]; + assert!(lcm(arr.span()) == Result::Err(LCMError::EmptyInput), "Empty inputs"); } diff --git a/src/math/src/tests/math_test.cairo b/src/math/src/tests/math_test.cairo index 1860cc8f..c14567a1 100644 --- a/src/math/src/tests/math_test.cairo +++ b/src/math/src/tests/math_test.cairo @@ -5,145 +5,145 @@ use integer::BoundedInt; #[test] #[available_gas(1000000000)] fn test_pow_power_2_all() { - assert(pow::(2, 0) == 1, '0'); - assert(pow::(2, 1) == 2, '1'); - assert(pow::(2, 2) == 4, '2'); - assert(pow::(2, 3) == 8, '3'); - assert(pow::(2, 4) == 16, '4'); - assert(pow::(2, 5) == 32, '5'); - assert(pow::(2, 6) == 64, '6'); - assert(pow::(2, 7) == 128, '7'); - assert(pow::(2, 8) == 256, '8'); - assert(pow::(2, 9) == 512, '9'); - assert(pow::(2, 10) == 1024, '10'); - assert(pow::(2, 11) == 2048, '11'); - assert(pow::(2, 12) == 4096, '12'); - assert(pow::(2, 13) == 8192, '13'); - assert(pow::(2, 14) == 16384, '14'); - assert(pow::(2, 15) == 32768, '15'); - assert(pow::(2, 16) == 65536, '16'); - assert(pow::(2, 17) == 131072, '17'); - assert(pow::(2, 18) == 262144, '18'); - assert(pow::(2, 19) == 524288, '19'); - assert(pow::(2, 20) == 1048576, '20'); - assert(pow::(2, 21) == 2097152, '21'); - assert(pow::(2, 22) == 4194304, '22'); - assert(pow::(2, 23) == 8388608, '23'); - assert(pow::(2, 24) == 16777216, '24'); - assert(pow::(2, 25) == 33554432, '25'); - assert(pow::(2, 26) == 67108864, '26'); - assert(pow::(2, 27) == 134217728, '27'); - assert(pow::(2, 28) == 268435456, '28'); - assert(pow::(2, 29) == 536870912, '29'); - assert(pow::(2, 30) == 1073741824, '30'); - assert(pow::(2, 31) == 2147483648, '31'); - assert(pow::(2, 32) == 4294967296, '32'); - assert(pow::(2, 33) == 8589934592, '33'); - assert(pow::(2, 34) == 17179869184, '34'); - assert(pow::(2, 35) == 34359738368, '35'); - assert(pow::(2, 36) == 68719476736, '36'); - assert(pow::(2, 37) == 137438953472, '37'); - assert(pow::(2, 38) == 274877906944, '38'); - assert(pow::(2, 39) == 549755813888, '39'); - assert(pow::(2, 40) == 1099511627776, '40'); - assert(pow::(2, 41) == 2199023255552, '41'); - assert(pow::(2, 42) == 4398046511104, '42'); - assert(pow::(2, 43) == 8796093022208, '43'); - assert(pow::(2, 44) == 17592186044416, '44'); - assert(pow::(2, 45) == 35184372088832, '45'); - assert(pow::(2, 46) == 70368744177664, '46'); - assert(pow::(2, 47) == 140737488355328, '47'); - assert(pow::(2, 48) == 281474976710656, '48'); - assert(pow::(2, 49) == 562949953421312, '49'); - assert(pow::(2, 50) == 1125899906842624, '50'); - assert(pow::(2, 51) == 2251799813685248, '51'); - assert(pow::(2, 52) == 4503599627370496, '52'); - assert(pow::(2, 53) == 9007199254740992, '53'); - assert(pow::(2, 54) == 18014398509481984, '54'); - assert(pow::(2, 55) == 36028797018963968, '55'); - assert(pow::(2, 56) == 72057594037927936, '56'); - assert(pow::(2, 57) == 144115188075855872, '57'); - assert(pow::(2, 58) == 288230376151711744, '58'); - assert(pow::(2, 59) == 576460752303423488, '59'); - assert(pow::(2, 60) == 1152921504606846976, '60'); - assert(pow::(2, 61) == 2305843009213693952, '61'); - assert(pow::(2, 62) == 4611686018427387904, '62'); - assert(pow::(2, 63) == 9223372036854775808, '63'); - assert(pow::(2, 64) == 18446744073709551616, '64'); - assert(pow::(2, 65) == 36893488147419103232, '65'); - assert(pow::(2, 66) == 73786976294838206464, '66'); - assert(pow::(2, 67) == 147573952589676412928, '67'); - assert(pow::(2, 68) == 295147905179352825856, '68'); - assert(pow::(2, 69) == 590295810358705651712, '69'); - assert(pow::(2, 70) == 1180591620717411303424, '70'); - assert(pow::(2, 71) == 2361183241434822606848, '71'); - assert(pow::(2, 72) == 4722366482869645213696, '72'); - assert(pow::(2, 73) == 9444732965739290427392, '73'); - assert(pow::(2, 74) == 18889465931478580854784, '74'); - assert(pow::(2, 75) == 37778931862957161709568, '75'); - assert(pow::(2, 76) == 75557863725914323419136, '76'); - assert(pow::(2, 77) == 151115727451828646838272, '77'); - assert(pow::(2, 78) == 302231454903657293676544, '78'); - assert(pow::(2, 79) == 604462909807314587353088, '79'); - assert(pow::(2, 80) == 1208925819614629174706176, '80'); - assert(pow::(2, 81) == 2417851639229258349412352, '81'); - assert(pow::(2, 82) == 4835703278458516698824704, '82'); - assert(pow::(2, 83) == 9671406556917033397649408, '83'); - assert(pow::(2, 84) == 19342813113834066795298816, '84'); - assert(pow::(2, 85) == 38685626227668133590597632, '85'); - assert(pow::(2, 86) == 77371252455336267181195264, '86'); - assert(pow::(2, 87) == 154742504910672534362390528, '87'); - assert(pow::(2, 88) == 309485009821345068724781056, '88'); - assert(pow::(2, 89) == 618970019642690137449562112, '89'); - assert(pow::(2, 90) == 1237940039285380274899124224, '90'); - assert(pow::(2, 91) == 2475880078570760549798248448, '91'); - assert(pow::(2, 92) == 4951760157141521099596496896, '92'); - assert(pow::(2, 93) == 9903520314283042199192993792, '93'); - assert(pow::(2, 94) == 19807040628566084398385987584, '94'); - assert(pow::(2, 95) == 39614081257132168796771975168, '95'); - assert(pow::(2, 96) == 79228162514264337593543950336, '96'); - assert(pow::(2, 97) == 158456325028528675187087900672, '97'); - assert(pow::(2, 98) == 316912650057057350374175801344, '98'); - assert(pow::(2, 99) == 633825300114114700748351602688, '99'); - assert(pow::(2, 100) == 1267650600228229401496703205376, '100'); - assert(pow::(2, 101) == 2535301200456458802993406410752, '101'); - assert(pow::(2, 102) == 5070602400912917605986812821504, '102'); - assert(pow::(2, 103) == 10141204801825835211973625643008, '103'); - assert(pow::(2, 104) == 20282409603651670423947251286016, '104'); - assert(pow::(2, 105) == 40564819207303340847894502572032, '105'); - assert(pow::(2, 106) == 81129638414606681695789005144064, '106'); - assert(pow::(2, 107) == 162259276829213363391578010288128, '107'); - assert(pow::(2, 108) == 324518553658426726783156020576256, '108'); - assert(pow::(2, 109) == 649037107316853453566312041152512, '109'); - assert(pow::(2, 110) == 1298074214633706907132624082305024, '110'); - assert(pow::(2, 111) == 2596148429267413814265248164610048, '111'); - assert(pow::(2, 112) == 5192296858534827628530496329220096, '112'); - assert(pow::(2, 113) == 10384593717069655257060992658440192, '113'); - assert(pow::(2, 114) == 20769187434139310514121985316880384, '114'); - assert(pow::(2, 115) == 41538374868278621028243970633760768, '115'); - assert(pow::(2, 116) == 83076749736557242056487941267521536, '116'); - assert(pow::(2, 117) == 166153499473114484112975882535043072, '117'); - assert(pow::(2, 118) == 332306998946228968225951765070086144, '118'); - assert(pow::(2, 119) == 664613997892457936451903530140172288, '119'); - assert(pow::(2, 120) == 1329227995784915872903807060280344576, '120'); - assert(pow::(2, 121) == 2658455991569831745807614120560689152, '121'); - assert(pow::(2, 122) == 5316911983139663491615228241121378304, '122'); - assert(pow::(2, 123) == 10633823966279326983230456482242756608, '123'); - assert(pow::(2, 124) == 21267647932558653966460912964485513216, '124'); - assert(pow::(2, 125) == 42535295865117307932921825928971026432, '125'); - assert(pow::(2, 126) == 85070591730234615865843651857942052864, '126'); - assert(pow::(2, 127) == 170141183460469231731687303715884105728, '127'); + assert_eq!(pow::(2, 0), 1, "0"); + assert_eq!(pow::(2, 1), 2, "1"); + assert_eq!(pow::(2, 2), 4, "2"); + assert_eq!(pow::(2, 3), 8, "3"); + assert_eq!(pow::(2, 4), 16, "4"); + assert_eq!(pow::(2, 5), 32, "5"); + assert_eq!(pow::(2, 6), 64, "6"); + assert_eq!(pow::(2, 7), 128, "7"); + assert_eq!(pow::(2, 8), 256, "8"); + assert_eq!(pow::(2, 9), 512, "9"); + assert_eq!(pow::(2, 10), 1024, "10"); + assert_eq!(pow::(2, 11), 2048, "11"); + assert_eq!(pow::(2, 12), 4096, "12"); + assert_eq!(pow::(2, 13), 8192, "13"); + assert_eq!(pow::(2, 14), 16384, "14"); + assert_eq!(pow::(2, 15), 32768, "15"); + assert_eq!(pow::(2, 16), 65536, "16"); + assert_eq!(pow::(2, 17), 131072, "17"); + assert_eq!(pow::(2, 18), 262144, "18"); + assert_eq!(pow::(2, 19), 524288, "19"); + assert_eq!(pow::(2, 20), 1048576, "20"); + assert_eq!(pow::(2, 21), 2097152, "21"); + assert_eq!(pow::(2, 22), 4194304, "22"); + assert_eq!(pow::(2, 23), 8388608, "23"); + assert_eq!(pow::(2, 24), 16777216, "24"); + assert_eq!(pow::(2, 25), 33554432, "25"); + assert_eq!(pow::(2, 26), 67108864, "26"); + assert_eq!(pow::(2, 27), 134217728, "27"); + assert_eq!(pow::(2, 28), 268435456, "28"); + assert_eq!(pow::(2, 29), 536870912, "29"); + assert_eq!(pow::(2, 30), 1073741824, "30"); + assert_eq!(pow::(2, 31), 2147483648, "31"); + assert_eq!(pow::(2, 32), 4294967296, "32"); + assert_eq!(pow::(2, 33), 8589934592, "33"); + assert_eq!(pow::(2, 34), 17179869184, "34"); + assert_eq!(pow::(2, 35), 34359738368, "35"); + assert_eq!(pow::(2, 36), 68719476736, "36"); + assert_eq!(pow::(2, 37), 137438953472, "37"); + assert_eq!(pow::(2, 38), 274877906944, "38"); + assert_eq!(pow::(2, 39), 549755813888, "39"); + assert_eq!(pow::(2, 40), 1099511627776, "40"); + assert_eq!(pow::(2, 41), 2199023255552, "41"); + assert_eq!(pow::(2, 42), 4398046511104, "42"); + assert_eq!(pow::(2, 43), 8796093022208, "43"); + assert_eq!(pow::(2, 44), 17592186044416, "44"); + assert_eq!(pow::(2, 45), 35184372088832, "45"); + assert_eq!(pow::(2, 46), 70368744177664, "46"); + assert_eq!(pow::(2, 47), 140737488355328, "47"); + assert_eq!(pow::(2, 48), 281474976710656, "48"); + assert_eq!(pow::(2, 49), 562949953421312, "49"); + assert_eq!(pow::(2, 50), 1125899906842624, "50"); + assert_eq!(pow::(2, 51), 2251799813685248, "51"); + assert_eq!(pow::(2, 52), 4503599627370496, "52"); + assert_eq!(pow::(2, 53), 9007199254740992, "53"); + assert_eq!(pow::(2, 54), 18014398509481984, "54"); + assert_eq!(pow::(2, 55), 36028797018963968, "55"); + assert_eq!(pow::(2, 56), 72057594037927936, "56"); + assert_eq!(pow::(2, 57), 144115188075855872, "57"); + assert_eq!(pow::(2, 58), 288230376151711744, "58"); + assert_eq!(pow::(2, 59), 576460752303423488, "59"); + assert_eq!(pow::(2, 60), 1152921504606846976, "60"); + assert_eq!(pow::(2, 61), 2305843009213693952, "61"); + assert_eq!(pow::(2, 62), 4611686018427387904, "62"); + assert_eq!(pow::(2, 63), 9223372036854775808, "63"); + assert_eq!(pow::(2, 64), 18446744073709551616, "64"); + assert_eq!(pow::(2, 65), 36893488147419103232, "65"); + assert_eq!(pow::(2, 66), 73786976294838206464, "66"); + assert_eq!(pow::(2, 67), 147573952589676412928, "67"); + assert_eq!(pow::(2, 68), 295147905179352825856, "68"); + assert_eq!(pow::(2, 69), 590295810358705651712, "69"); + assert_eq!(pow::(2, 70), 1180591620717411303424, "70"); + assert_eq!(pow::(2, 71), 2361183241434822606848, "71"); + assert_eq!(pow::(2, 72), 4722366482869645213696, "72"); + assert_eq!(pow::(2, 73), 9444732965739290427392, "73"); + assert_eq!(pow::(2, 74), 18889465931478580854784, "74"); + assert_eq!(pow::(2, 75), 37778931862957161709568, "75"); + assert_eq!(pow::(2, 76), 75557863725914323419136, "76"); + assert_eq!(pow::(2, 77), 151115727451828646838272, "77"); + assert_eq!(pow::(2, 78), 302231454903657293676544, "78"); + assert_eq!(pow::(2, 79), 604462909807314587353088, "79"); + assert_eq!(pow::(2, 80), 1208925819614629174706176, "80"); + assert_eq!(pow::(2, 81), 2417851639229258349412352, "81"); + assert_eq!(pow::(2, 82), 4835703278458516698824704, "82"); + assert_eq!(pow::(2, 83), 9671406556917033397649408, "83"); + assert_eq!(pow::(2, 84), 19342813113834066795298816, "84"); + assert_eq!(pow::(2, 85), 38685626227668133590597632, "85"); + assert_eq!(pow::(2, 86), 77371252455336267181195264, "86"); + assert_eq!(pow::(2, 87), 154742504910672534362390528, "87"); + assert_eq!(pow::(2, 88), 309485009821345068724781056, "88"); + assert_eq!(pow::(2, 89), 618970019642690137449562112, "89"); + assert_eq!(pow::(2, 90), 1237940039285380274899124224, "90"); + assert_eq!(pow::(2, 91), 2475880078570760549798248448, "91"); + assert_eq!(pow::(2, 92), 4951760157141521099596496896, "92"); + assert_eq!(pow::(2, 93), 9903520314283042199192993792, "93"); + assert_eq!(pow::(2, 94), 19807040628566084398385987584, "94"); + assert_eq!(pow::(2, 95), 39614081257132168796771975168, "95"); + assert_eq!(pow::(2, 96), 79228162514264337593543950336, "96"); + assert_eq!(pow::(2, 97), 158456325028528675187087900672, "97"); + assert_eq!(pow::(2, 98), 316912650057057350374175801344, "98"); + assert_eq!(pow::(2, 99), 633825300114114700748351602688, "99"); + assert_eq!(pow::(2, 100), 1267650600228229401496703205376, "100"); + assert_eq!(pow::(2, 101), 2535301200456458802993406410752, "101"); + assert_eq!(pow::(2, 102), 5070602400912917605986812821504, "102"); + assert_eq!(pow::(2, 103), 10141204801825835211973625643008, "103"); + assert_eq!(pow::(2, 104), 20282409603651670423947251286016, "104"); + assert_eq!(pow::(2, 105), 40564819207303340847894502572032, "105"); + assert_eq!(pow::(2, 106), 81129638414606681695789005144064, "106"); + assert_eq!(pow::(2, 107), 162259276829213363391578010288128, "107"); + assert_eq!(pow::(2, 108), 324518553658426726783156020576256, "108"); + assert_eq!(pow::(2, 109), 649037107316853453566312041152512, "109"); + assert_eq!(pow::(2, 110), 1298074214633706907132624082305024, "110"); + assert_eq!(pow::(2, 111), 2596148429267413814265248164610048, "111"); + assert_eq!(pow::(2, 112), 5192296858534827628530496329220096, "112"); + assert_eq!(pow::(2, 113), 10384593717069655257060992658440192, "113"); + assert_eq!(pow::(2, 114), 20769187434139310514121985316880384, "114"); + assert_eq!(pow::(2, 115), 41538374868278621028243970633760768, "115"); + assert_eq!(pow::(2, 116), 83076749736557242056487941267521536, "116"); + assert_eq!(pow::(2, 117), 166153499473114484112975882535043072, "117"); + assert_eq!(pow::(2, 118), 332306998946228968225951765070086144, "118"); + assert_eq!(pow::(2, 119), 664613997892457936451903530140172288, "119"); + assert_eq!(pow::(2, 120), 1329227995784915872903807060280344576, "120"); + assert_eq!(pow::(2, 121), 2658455991569831745807614120560689152, "121"); + assert_eq!(pow::(2, 122), 5316911983139663491615228241121378304, "122"); + assert_eq!(pow::(2, 123), 10633823966279326983230456482242756608, "123"); + assert_eq!(pow::(2, 124), 21267647932558653966460912964485513216, "124"); + assert_eq!(pow::(2, 125), 42535295865117307932921825928971026432, "125"); + assert_eq!(pow::(2, 126), 85070591730234615865843651857942052864, "126"); + assert_eq!(pow::(2, 127), 170141183460469231731687303715884105728, "127"); } #[test] #[available_gas(2000000)] fn pow_test() { - assert(pow::(200, 0) == 1, '200^0'); - assert(pow::(5, 9) == 1953125, '5^9'); - assert(pow::(14, 30) == 24201432355484595421941037243826176, '14^30'); - assert(pow::(3, 8) == 6561, '3^8_u128'); - assert(pow::(3, 8) == 6561, '3^8_u256'); + assert_eq!(pow::(200, 0), 1, "200^0"); + assert_eq!(pow::(5, 9), 1953125, "5^9"); + assert_eq!(pow::(14, 30), 24201432355484595421941037243826176, "14^30"); + assert_eq!(pow::(3, 8), 6561, "3^8_u128"); + assert_eq!(pow::(3, 8), 6561, "3^8_u256"); } @@ -151,52 +151,52 @@ fn pow_test() { #[test] #[available_gas(2000000)] fn count_digits_of_base_test() { - assert(count_digits_of_base(0, 10) == 0, 'invalid result'); - assert(count_digits_of_base(2, 10) == 1, 'invalid result'); - assert(count_digits_of_base(10, 10) == 2, 'invalid result'); - assert(count_digits_of_base(100, 10) == 3, 'invalid result'); - assert(count_digits_of_base(0x80, 16) == 2, 'invalid result'); - assert(count_digits_of_base(0x800, 16) == 3, 'invalid result'); - assert(count_digits_of_base(0x888888888888888888, 16) == 18, 'invalid result'); + assert_eq!(count_digits_of_base(0, 10), 0, "invalid result"); + assert_eq!(count_digits_of_base(2, 10), 1, "invalid result"); + assert_eq!(count_digits_of_base(10, 10), 2, "invalid result"); + assert_eq!(count_digits_of_base(100, 10), 3, "invalid result"); + assert_eq!(count_digits_of_base(0x80, 16), 2, "invalid result"); + assert_eq!(count_digits_of_base(0x800, 16), 3, "invalid result"); + assert_eq!(count_digits_of_base(0x888888888888888888, 16), 18, "invalid result"); } #[test] #[available_gas(2000000)] fn shl_should_not_overflow() { - assert(BitShift::shl(pow::(2, 7), 1) == 0, 'invalid result'); - assert(BitShift::shl(pow::(2, 15), 1) == 0, 'invalid result'); - assert(BitShift::shl(pow::(2, 31), 1) == 0, 'invalid result'); - assert(BitShift::shl(pow::(2, 63), 1) == 0, 'invalid result'); - assert(BitShift::shl(pow::(2, 127), 1) == 0, 'invalid result'); - assert(BitShift::shl(pow::(2, 255), 1) == 0, 'invalid result'); + assert_eq!(BitShift::shl(pow::(2, 7), 1), 0, "invalid result"); + assert_eq!(BitShift::shl(pow::(2, 15), 1), 0, "invalid result"); + assert_eq!(BitShift::shl(pow::(2, 31), 1), 0, "invalid result"); + assert_eq!(BitShift::shl(pow::(2, 63), 1), 0, "invalid result"); + assert_eq!(BitShift::shl(pow::(2, 127), 1), 0, "invalid result"); + assert_eq!(BitShift::shl(pow::(2, 255), 1), 0, "invalid result"); } #[test] #[available_gas(3000000)] fn test_rotl_min() { - assert(BitRotate::rotate_left(pow::(2, 7) + 1, 1) == 3, 'invalid result'); - assert(BitRotate::rotate_left(pow::(2, 15) + 1, 1) == 3, 'invalid result'); - assert(BitRotate::rotate_left(pow::(2, 31) + 1, 1) == 3, 'invalid result'); - assert(BitRotate::rotate_left(pow::(2, 63) + 1, 1) == 3, 'invalid result'); - assert(BitRotate::rotate_left(pow::(2, 127) + 1, 1) == 3, 'invalid result'); - assert(BitRotate::rotate_left(pow::(2, 255) + 1, 1) == 3, 'invalid result'); + assert_eq!(BitRotate::rotate_left(pow::(2, 7) + 1, 1), 3, "invalid result"); + assert_eq!(BitRotate::rotate_left(pow::(2, 15) + 1, 1), 3, "invalid result"); + assert_eq!(BitRotate::rotate_left(pow::(2, 31) + 1, 1), 3, "invalid result"); + assert_eq!(BitRotate::rotate_left(pow::(2, 63) + 1, 1), 3, "invalid result"); + assert_eq!(BitRotate::rotate_left(pow::(2, 127) + 1, 1), 3, "invalid result"); + assert_eq!(BitRotate::rotate_left(pow::(2, 255) + 1, 1), 3, "invalid result"); } #[test] #[available_gas(3000000)] fn test_rotl_max() { - assert(BitRotate::rotate_left(0b101, 7) == pow::(2, 7) + 0b10, 'invalid result'); - assert(BitRotate::rotate_left(0b101, 15) == pow::(2, 15) + 0b10, 'invalid result'); - assert(BitRotate::rotate_left(0b101, 31) == pow::(2, 31) + 0b10, 'invalid result'); - assert(BitRotate::rotate_left(0b101, 63) == pow::(2, 63) + 0b10, 'invalid result'); - assert(BitRotate::rotate_left(0b101, 127) == pow::(2, 127) + 0b10, 'invalid result'); - assert(BitRotate::rotate_left(0b101, 255) == pow::(2, 255) + 0b10, 'invalid result'); + assert_eq!(BitRotate::rotate_left(0b101, 7), pow::(2, 7) + 0b10, "invalid result"); + assert_eq!(BitRotate::rotate_left(0b101, 15), pow::(2, 15) + 0b10, "invalid result"); + assert_eq!(BitRotate::rotate_left(0b101, 31), pow::(2, 31) + 0b10, "invalid result"); + assert_eq!(BitRotate::rotate_left(0b101, 63), pow::(2, 63) + 0b10, "invalid result"); + assert_eq!(BitRotate::rotate_left(0b101, 127), pow::(2, 127) + 0b10, "invalid result"); + assert_eq!(BitRotate::rotate_left(0b101, 255), pow::(2, 255) + 0b10, "invalid result"); } #[test] #[available_gas(4000000)] fn test_rotr_min() { - assert(BitRotate::rotate_right(pow::(2, 7) + 1, 1) == 0b11 * pow(2, 6), 'invalid result'); + assert_eq!(BitRotate::rotate_right(pow::(2, 7) + 1, 1), 0b11 * pow(2, 6), "invalid result"); assert( BitRotate::rotate_right(pow::(2, 15) + 1, 1) == 0b11 * pow(2, 14), 'invalid result' ); @@ -217,12 +217,12 @@ fn test_rotr_min() { #[test] #[available_gas(2000000)] fn test_rotr_max() { - assert(BitRotate::rotate_right(0b101_u8, 7) == 0b1010, 'invalid result'); - assert(BitRotate::rotate_right(0b101_u16, 15) == 0b1010, 'invalid result'); - assert(BitRotate::rotate_right(0b101_u32, 31) == 0b1010, 'invalid result'); - assert(BitRotate::rotate_right(0b101_u64, 63) == 0b1010, 'invalid result'); - assert(BitRotate::rotate_right(0b101_u128, 127) == 0b1010, 'invalid result'); - assert(BitRotate::rotate_right(0b101_u256, 255) == 0b1010, 'invalid result'); + assert_eq!(BitRotate::rotate_right(0b101_u8, 7), 0b1010, "invalid result"); + assert_eq!(BitRotate::rotate_right(0b101_u16, 15), 0b1010, "invalid result"); + assert_eq!(BitRotate::rotate_right(0b101_u32, 31), 0b1010, "invalid result"); + assert_eq!(BitRotate::rotate_right(0b101_u64, 63), 0b1010, "invalid result"); + assert_eq!(BitRotate::rotate_right(0b101_u128, 127), 0b1010, "invalid result"); + assert_eq!(BitRotate::rotate_right(0b101_u256, 255), 0b1010, "invalid result"); } #[test] diff --git a/src/math/src/tests/mod_arithmetics_test.cairo b/src/math/src/tests/mod_arithmetics_test.cairo index 0bc9e5b9..a6bb8ca6 100644 --- a/src/math/src/tests/mod_arithmetics_test.cairo +++ b/src/math/src/tests/mod_arithmetics_test.cairo @@ -9,107 +9,107 @@ const pow_256_minus_1: u256 = #[test] #[available_gas(500000000)] fn add_mod_p_test() { - assert(add_mod(p, p, p) == 0, 'Incorrect result'); - assert(add_mod(p, 1, p) == 1, 'Incorrect result'); - assert(add_mod(1, p, p) == 1, 'Incorrect result'); - assert(add_mod(10, 30, p) == 40, 'Incorrect result'); - assert(add_mod(0, 0, p) == 0, 'Incorrect result'); - assert(add_mod(0, 1, p) == 1, 'Incorrect result'); - assert(add_mod(1, 0, p) == 1, 'Incorrect result'); - assert(add_mod(pow_256_minus_1, 1, p) == 38, 'Incorrect result'); + assert_eq!(add_mod(p, p, p), 0, "Incorrect result"); + assert_eq!(add_mod(p, 1, p), 1, "Incorrect result"); + assert_eq!(add_mod(1, p, p), 1, "Incorrect result"); + assert_eq!(add_mod(10, 30, p), 40, "Incorrect result"); + assert_eq!(add_mod(0, 0, p), 0, "Incorrect result"); + assert_eq!(add_mod(0, 1, p), 1, "Incorrect result"); + assert_eq!(add_mod(1, 0, p), 1, "Incorrect result"); + assert_eq!(add_mod(pow_256_minus_1, 1, p), 38, "Incorrect result"); } #[test] #[available_gas(500000000)] fn add_mod_2_test() { - assert(add_mod(p, 2, 2) == 1, 'Incorrect result'); - assert(add_mod(p, 1, 2) == 0, 'Incorrect result'); + assert_eq!(add_mod(p, 2, 2), 1, "Incorrect result"); + assert_eq!(add_mod(p, 1, 2), 0, "Incorrect result"); } #[test] #[available_gas(500000000)] fn add_mod_1_test() { - assert(add_mod(p, 2, 1) == 0, 'Incorrect result'); - assert(add_mod(p, p, 1) == 0, 'Incorrect result'); - assert(add_mod(0, 0, 1) == 0, 'Incorrect result'); + assert_eq!(add_mod(p, 2, 1), 0, "Incorrect result"); + assert_eq!(add_mod(p, p, 1), 0, "Incorrect result"); + assert_eq!(add_mod(0, 0, 1), 0, "Incorrect result"); } #[test] #[available_gas(500000000)] fn sub_mod_test() { - assert(sub_mod(p, p, p) == 0, 'Incorrect result'); - assert(sub_mod(p, 1, p) == (p - 1), 'Incorrect result'); - assert(sub_mod(1, p, p) == 1, 'Incorrect result'); - assert(sub_mod(10, 30, p) == (p - 30 + 10), 'Incorrect result'); - assert(sub_mod(0, 0, p) == 0, 'Incorrect result'); - assert(sub_mod(0, 1, p) == (p - 1), 'Incorrect result'); - assert(sub_mod(1, 0, p) == 1, 'Incorrect result'); - assert(sub_mod(pow_256_minus_1, 1, p) == 36, 'Incorrect result'); + assert_eq!(sub_mod(p, p, p), 0, "Incorrect result"); + assert_eq!(sub_mod(p, 1, p), (p - 1), "Incorrect result"); + assert_eq!(sub_mod(1, p, p), 1, "Incorrect result"); + assert_eq!(sub_mod(10, 30, p), (p - 30 + 10), "Incorrect result"); + assert_eq!(sub_mod(0, 0, p), 0, "Incorrect result"); + assert_eq!(sub_mod(0, 1, p), (p - 1), "Incorrect result"); + assert_eq!(sub_mod(1, 0, p), 1, "Incorrect result"); + assert_eq!(sub_mod(pow_256_minus_1, 1, p), 36, "Incorrect result"); } #[test] #[available_gas(500000000)] fn sub_mod_1_test() { - assert(sub_mod(p, p, 1) == 0, 'Incorrect result'); - assert(sub_mod(p, 1, 1) == 0, 'Incorrect result'); - assert(sub_mod(1, p, 1) == 0, 'Incorrect result'); - assert(sub_mod(10, 30, 1) == 0, 'Incorrect result'); - assert(sub_mod(0, 0, 1) == 0, 'Incorrect result'); - assert(sub_mod(0, 1, 1) == 0, 'Incorrect result'); - assert(sub_mod(1, 0, 1) == 0, 'Incorrect result'); - assert(sub_mod(pow_256_minus_1, 1, 1) == 0, 'Incorrect result'); + assert_eq!(sub_mod(p, p, 1), 0, "Incorrect result"); + assert_eq!(sub_mod(p, 1, 1), 0, "Incorrect result"); + assert_eq!(sub_mod(1, p, 1), 0, "Incorrect result"); + assert_eq!(sub_mod(10, 30, 1), 0, "Incorrect result"); + assert_eq!(sub_mod(0, 0, 1), 0, "Incorrect result"); + assert_eq!(sub_mod(0, 1, 1), 0, "Incorrect result"); + assert_eq!(sub_mod(1, 0, 1), 0, "Incorrect result"); + assert_eq!(sub_mod(pow_256_minus_1, 1, 1), 0, "Incorrect result"); } #[test] #[available_gas(500000000)] fn sub_mod_2_test() { - assert(sub_mod(p, p, 2) == 0, 'Incorrect result'); - assert(sub_mod(p, 1, 2) == 0, 'Incorrect result'); - assert(sub_mod(1, p, 2) == 0, 'Incorrect result'); - assert(sub_mod(10, 30, 2) == 0, 'Incorrect result'); - assert(sub_mod(0, 0, 2) == 0, 'Incorrect result'); - assert(sub_mod(0, 1, 2) == 1, 'Incorrect result'); - assert(sub_mod(1, 0, 2) == 1, 'Incorrect result'); - assert(sub_mod(pow_256_minus_1, 1, 2) == 0, 'Incorrect result'); + assert_eq!(sub_mod(p, p, 2), 0, "Incorrect result"); + assert_eq!(sub_mod(p, 1, 2), 0, "Incorrect result"); + assert_eq!(sub_mod(1, p, 2), 0, "Incorrect result"); + assert_eq!(sub_mod(10, 30, 2), 0, "Incorrect result"); + assert_eq!(sub_mod(0, 0, 2), 0, "Incorrect result"); + assert_eq!(sub_mod(0, 1, 2), 1, "Incorrect result"); + assert_eq!(sub_mod(1, 0, 2), 1, "Incorrect result"); + assert_eq!(sub_mod(pow_256_minus_1, 1, 2), 0, "Incorrect result"); } #[test] #[available_gas(500000000)] fn mult_mod_test() { - assert(mult_mod(p, p, p) == 0, 'Incorrect result'); - assert(mult_mod(p, 1, p) == 0, 'Incorrect result'); - assert(mult_mod(1, p, p) == 0, 'Incorrect result'); - assert(mult_mod(10, 30, p) == 300, 'Incorrect result'); - assert(mult_mod(0, 0, p) == 0, 'Incorrect result'); - assert(mult_mod(0, 1, p) == 0, 'Incorrect result'); - assert(mult_mod(1, 0, p) == 0, 'Incorrect result'); - assert(mult_mod(pow_256_minus_1, 1, p) == 37, 'Incorrect result'); + assert_eq!(mult_mod(p, p, p), 0, "Incorrect result"); + assert_eq!(mult_mod(p, 1, p), 0, "Incorrect result"); + assert_eq!(mult_mod(1, p, p), 0, "Incorrect result"); + assert_eq!(mult_mod(10, 30, p), 300, "Incorrect result"); + assert_eq!(mult_mod(0, 0, p), 0, "Incorrect result"); + assert_eq!(mult_mod(0, 1, p), 0, "Incorrect result"); + assert_eq!(mult_mod(1, 0, p), 0, "Incorrect result"); + assert_eq!(mult_mod(pow_256_minus_1, 1, p), 37, "Incorrect result"); } #[test] #[available_gas(500000000)] fn mult_mod_1_test() { - assert(mult_mod(p, p, 1) == 0, 'Incorrect result'); - assert(mult_mod(p, 1, 1) == 0, 'Incorrect result'); - assert(mult_mod(1, p, 1) == 0, 'Incorrect result'); - assert(mult_mod(10, 30, 1) == 0, 'Incorrect result'); - assert(mult_mod(0, 0, 1) == 0, 'Incorrect result'); - assert(mult_mod(0, 1, 1) == 0, 'Incorrect result'); - assert(mult_mod(1, 0, 1) == 0, 'Incorrect result'); - assert(mult_mod(pow_256_minus_1, 1, 1) == 0, 'Incorrect result'); + assert_eq!(mult_mod(p, p, 1), 0, "Incorrect result"); + assert_eq!(mult_mod(p, 1, 1), 0, "Incorrect result"); + assert_eq!(mult_mod(1, p, 1), 0, "Incorrect result"); + assert_eq!(mult_mod(10, 30, 1), 0, "Incorrect result"); + assert_eq!(mult_mod(0, 0, 1), 0, "Incorrect result"); + assert_eq!(mult_mod(0, 1, 1), 0, "Incorrect result"); + assert_eq!(mult_mod(1, 0, 1), 0, "Incorrect result"); + assert_eq!(mult_mod(pow_256_minus_1, 1, 1), 0, "Incorrect result"); } #[test] #[available_gas(500000000)] fn mult_mod_2_test() { - assert(mult_mod(p, p, 2) == 1, 'Incorrect result'); - assert(mult_mod(p, 1, 2) == 1, 'Incorrect result'); - assert(mult_mod(1, p, 2) == 1, 'Incorrect result'); - assert(mult_mod(10, 30, 2) == 0, 'Incorrect result'); - assert(mult_mod(0, 0, 2) == 0, 'Incorrect result'); - assert(mult_mod(0, 1, 2) == 0, 'Incorrect result'); - assert(mult_mod(1, 0, 2) == 0, 'Incorrect result'); - assert(mult_mod(pow_256_minus_1, 1, 2) == 1, 'Incorrect result'); + assert_eq!(mult_mod(p, p, 2), 1, "Incorrect result"); + assert_eq!(mult_mod(p, 1, 2), 1, "Incorrect result"); + assert_eq!(mult_mod(1, p, 2), 1, "Incorrect result"); + assert_eq!(mult_mod(10, 30, 2), 0, "Incorrect result"); + assert_eq!(mult_mod(0, 0, 2), 0, "Incorrect result"); + assert_eq!(mult_mod(0, 1, 2), 0, "Incorrect result"); + assert_eq!(mult_mod(1, 0, 2), 0, "Incorrect result"); + assert_eq!(mult_mod(pow_256_minus_1, 1, 2), 1, "Incorrect result"); } #[test] @@ -117,45 +117,45 @@ fn mult_mod_2_test() { fn div_mod_test() { let div_10_30_mod_p = 38597363079105398474523661669562635951089994888546854679819194669304376546633; - assert(div_mod(p, 1, p) == 0, 'Incorrect result'); - assert(div_mod(30, 10, p) == 3, 'Incorrect result'); - assert(div_mod(10, 30, p) == div_10_30_mod_p, 'Incorrect result'); + assert_eq!(div_mod(p, 1, p), 0, "Incorrect result"); + assert_eq!(div_mod(30, 10, p), 3, "Incorrect result"); + assert_eq!(div_mod(10, 30, p), div_10_30_mod_p, "Incorrect result"); } #[test] #[available_gas(500000000)] fn pow_mod_test() { - assert(pow_mod(2, 4, p) == 16, 'Incorrect result'); - assert(pow_mod(2, 256, p) == 38, 'Incorrect result'); - assert(pow_mod(2, 260, p) == 608, 'Incorrect result'); + assert_eq!(pow_mod(2, 4, p), 16, "Incorrect result"); + assert_eq!(pow_mod(2, 256, p), 38, "Incorrect result"); + assert_eq!(pow_mod(2, 260, p), 608, "Incorrect result"); assert( pow_mod( 10, 260, p ) == 17820046977743035104984469918379927979184337110507416960697246160624073120874, 'Incorrect result' ); - assert(pow_mod(4, 174, p) == 188166885971377801784666882048, 'Incorrect result'); - assert(pow_mod(100, p, p) == 100, 'Incorrect result'); + assert_eq!(pow_mod(4, 174, p), 188166885971377801784666882048, "Incorrect result"); + assert_eq!(pow_mod(100, p, p), 100, "Incorrect result"); } #[test] #[available_gas(500000000)] fn pow_mod_1_test() { - assert(pow_mod(2, 4, 1) == 0, 'Incorrect result'); - assert(pow_mod(2, 256, 1) == 0, 'Incorrect result'); - assert(pow_mod(2, 260, 1) == 0, 'Incorrect result'); - assert(pow_mod(10, 260, 1) == 0, 'Incorrect result'); - assert(pow_mod(4, 174, 1) == 0, 'Incorrect result'); - assert(pow_mod(100, p, 1) == 0, 'Incorrect result'); + assert_eq!(pow_mod(2, 4, 1), 0, "Incorrect result"); + assert_eq!(pow_mod(2, 256, 1), 0, "Incorrect result"); + assert_eq!(pow_mod(2, 260, 1), 0, "Incorrect result"); + assert_eq!(pow_mod(10, 260, 1), 0, "Incorrect result"); + assert_eq!(pow_mod(4, 174, 1), 0, "Incorrect result"); + assert_eq!(pow_mod(100, p, 1), 0, "Incorrect result"); } #[test] #[available_gas(500000000)] fn pow_mod_2_test() { - assert(pow_mod(2, 4, 2) == 0, 'Incorrect result'); - assert(pow_mod(2, 256, 2) == 0, 'Incorrect result'); - assert(pow_mod(2, 260, 2) == 0, 'Incorrect result'); - assert(pow_mod(10, 260, 2) == 0, 'Incorrect result'); - assert(pow_mod(4, 174, 2) == 0, 'Incorrect result'); - assert(pow_mod(100, p, 2) == 0, 'Incorrect result'); + assert_eq!(pow_mod(2, 4, 2), 0, "Incorrect result"); + assert_eq!(pow_mod(2, 256, 2), 0, "Incorrect result"); + assert_eq!(pow_mod(2, 260, 2), 0, "Incorrect result"); + assert_eq!(pow_mod(10, 260, 2), 0, "Incorrect result"); + assert_eq!(pow_mod(4, 174, 2), 0, "Incorrect result"); + assert_eq!(pow_mod(100, p, 2), 0, "Incorrect result"); } diff --git a/src/math/src/tests/perfect_number_test.cairo b/src/math/src/tests/perfect_number_test.cairo index c00cb08c..10f2dd71 100644 --- a/src/math/src/tests/perfect_number_test.cairo +++ b/src/math/src/tests/perfect_number_test.cairo @@ -4,27 +4,27 @@ use alexandria_math::perfect_number::{is_perfect_number, perfect_numbers}; #[test] #[available_gas(2000000)] fn perfect_small_number_test() { - assert(is_perfect_number(6), 'invalid result'); - assert(is_perfect_number(28), 'invalid result'); + assert!(is_perfect_number(6), "invalid result"); + assert!(is_perfect_number(28), "invalid result"); } #[test] #[available_gas(20000000)] fn perfect_big_number_test() { - assert(is_perfect_number(496), 'invalid result'); + assert!(is_perfect_number(496), "invalid result"); } #[test] #[available_gas(20000000)] fn not_perfect_small_number_test() { - assert(!is_perfect_number(5), 'invalid result'); - assert(!is_perfect_number(86), 'invalid result'); + assert!(!is_perfect_number(5), "invalid result"); + assert!(!is_perfect_number(86), "invalid result"); } #[test] #[available_gas(20000000)] fn not_perfect_big_number_test() { - assert(!is_perfect_number(497), 'invalid result'); + assert!(!is_perfect_number(497), "invalid result"); } // perfect_numbers @@ -32,5 +32,5 @@ fn not_perfect_big_number_test() { #[available_gas(2000000)] fn perfect_numbers_test() { let mut res = perfect_numbers(10); - assert(res.len() == 1, 'invalid result'); + assert_eq!(res.len(), 1, "invalid result"); } diff --git a/src/math/src/tests/sha256_test.cairo b/src/math/src/tests/sha256_test.cairo index 3f528977..b1aea050 100644 --- a/src/math/src/tests/sha256_test.cairo +++ b/src/math/src/tests/sha256_test.cairo @@ -7,39 +7,39 @@ fn sha256_empty_test() { let result = sha256::sha256(input); // result should be 0xE3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 - assert(result.len() == 32, 'invalid result length'); - assert(*result[0] == 0xE3, 'invalid result'); - assert(*result[1] == 0xB0, 'invalid result'); - assert(*result[2] == 0xC4, 'invalid result'); - assert(*result[3] == 0x42, 'invalid result'); - assert(*result[4] == 0x98, 'invalid result'); - assert(*result[5] == 0xFC, 'invalid result'); - assert(*result[6] == 0x1C, 'invalid result'); - assert(*result[7] == 0x14, 'invalid result'); - assert(*result[8] == 0x9A, 'invalid result'); - assert(*result[9] == 0xFB, 'invalid result'); - assert(*result[10] == 0xF4, 'invalid result'); - assert(*result[11] == 0xC8, 'invalid result'); - assert(*result[12] == 0x99, 'invalid result'); - assert(*result[13] == 0x6F, 'invalid result'); - assert(*result[14] == 0xB9, 'invalid result'); - assert(*result[15] == 0x24, 'invalid result'); - assert(*result[16] == 0x27, 'invalid result'); - assert(*result[17] == 0xAE, 'invalid result'); - assert(*result[18] == 0x41, 'invalid result'); - assert(*result[19] == 0xE4, 'invalid result'); - assert(*result[20] == 0x64, 'invalid result'); - assert(*result[21] == 0x9B, 'invalid result'); - assert(*result[22] == 0x93, 'invalid result'); - assert(*result[23] == 0x4C, 'invalid result'); - assert(*result[24] == 0xA4, 'invalid result'); - assert(*result[25] == 0x95, 'invalid result'); - assert(*result[26] == 0x99, 'invalid result'); - assert(*result[27] == 0x1B, 'invalid result'); - assert(*result[28] == 0x78, 'invalid result'); - assert(*result[29] == 0x52, 'invalid result'); - assert(*result[30] == 0xB8, 'invalid result'); - assert(*result[31] == 0x55, 'invalid result'); + assert_eq!(result.len(), 32, "invalid result length"); + assert_eq!(*result[0], 0xE3, "invalid result"); + assert_eq!(*result[1], 0xB0, "invalid result"); + assert_eq!(*result[2], 0xC4, "invalid result"); + assert_eq!(*result[3], 0x42, "invalid result"); + assert_eq!(*result[4], 0x98, "invalid result"); + assert_eq!(*result[5], 0xFC, "invalid result"); + assert_eq!(*result[6], 0x1C, "invalid result"); + assert_eq!(*result[7], 0x14, "invalid result"); + assert_eq!(*result[8], 0x9A, "invalid result"); + assert_eq!(*result[9], 0xFB, "invalid result"); + assert_eq!(*result[10], 0xF4, "invalid result"); + assert_eq!(*result[11], 0xC8, "invalid result"); + assert_eq!(*result[12], 0x99, "invalid result"); + assert_eq!(*result[13], 0x6F, "invalid result"); + assert_eq!(*result[14], 0xB9, "invalid result"); + assert_eq!(*result[15], 0x24, "invalid result"); + assert_eq!(*result[16], 0x27, "invalid result"); + assert_eq!(*result[17], 0xAE, "invalid result"); + assert_eq!(*result[18], 0x41, "invalid result"); + assert_eq!(*result[19], 0xE4, "invalid result"); + assert_eq!(*result[20], 0x64, "invalid result"); + assert_eq!(*result[21], 0x9B, "invalid result"); + assert_eq!(*result[22], 0x93, "invalid result"); + assert_eq!(*result[23], 0x4C, "invalid result"); + assert_eq!(*result[24], 0xA4, "invalid result"); + assert_eq!(*result[25], 0x95, "invalid result"); + assert_eq!(*result[26], 0x99, "invalid result"); + assert_eq!(*result[27], 0x1B, "invalid result"); + assert_eq!(*result[28], 0x78, "invalid result"); + assert_eq!(*result[29], 0x52, "invalid result"); + assert_eq!(*result[30], 0xB8, "invalid result"); + assert_eq!(*result[31], 0x55, "invalid result"); } #[test] @@ -49,38 +49,38 @@ fn sha256_random_data_test() { 0x57, 0x77, 0x71, 0x71, 0x66, 0x50, 0x45, 0x51, 0x51, 0x43, 0x39, 0x48, 0x38 ]; let result = sha256::sha256(input); - assert(*result[0] == 61, 'invalid result'); - assert(*result[1] == 226, 'invalid result'); - assert(*result[2] == 188, 'invalid result'); - assert(*result[3] == 242, 'invalid result'); - assert(*result[4] == 118, 'invalid result'); - assert(*result[5] == 121, 'invalid result'); - assert(*result[6] == 7, 'invalid result'); - assert(*result[7] == 225, 'invalid result'); - assert(*result[8] == 150, 'invalid result'); - assert(*result[9] == 220, 'invalid result'); - assert(*result[10] == 105, 'invalid result'); - assert(*result[11] == 158, 'invalid result'); - assert(*result[12] == 185, 'invalid result'); - assert(*result[13] == 180, 'invalid result'); - assert(*result[14] == 139, 'invalid result'); - assert(*result[15] == 103, 'invalid result'); - assert(*result[16] == 221, 'invalid result'); - assert(*result[17] == 95, 'invalid result'); - assert(*result[18] == 56, 'invalid result'); - assert(*result[19] == 88, 'invalid result'); - assert(*result[20] == 209, 'invalid result'); - assert(*result[21] == 159, 'invalid result'); - assert(*result[22] == 255, 'invalid result'); - assert(*result[23] == 247, 'invalid result'); - assert(*result[24] == 145, 'invalid result'); - assert(*result[25] == 146, 'invalid result'); - assert(*result[26] == 83, 'invalid result'); - assert(*result[27] == 110, 'invalid result'); - assert(*result[28] == 185, 'invalid result'); - assert(*result[29] == 5, 'invalid result'); - assert(*result[30] == 248, 'invalid result'); - assert(*result[31] == 15, 'invalid result'); + assert_eq!(*result[0], 61, "invalid result"); + assert_eq!(*result[1], 226, "invalid result"); + assert_eq!(*result[2], 188, "invalid result"); + assert_eq!(*result[3], 242, "invalid result"); + assert_eq!(*result[4], 118, "invalid result"); + assert_eq!(*result[5], 121, "invalid result"); + assert_eq!(*result[6], 7, "invalid result"); + assert_eq!(*result[7], 225, "invalid result"); + assert_eq!(*result[8], 150, "invalid result"); + assert_eq!(*result[9], 220, "invalid result"); + assert_eq!(*result[10], 105, "invalid result"); + assert_eq!(*result[11], 158, "invalid result"); + assert_eq!(*result[12], 185, "invalid result"); + assert_eq!(*result[13], 180, "invalid result"); + assert_eq!(*result[14], 139, "invalid result"); + assert_eq!(*result[15], 103, "invalid result"); + assert_eq!(*result[16], 221, "invalid result"); + assert_eq!(*result[17], 95, "invalid result"); + assert_eq!(*result[18], 56, "invalid result"); + assert_eq!(*result[19], 88, "invalid result"); + assert_eq!(*result[20], 209, "invalid result"); + assert_eq!(*result[21], 159, "invalid result"); + assert_eq!(*result[22], 255, "invalid result"); + assert_eq!(*result[23], 247, "invalid result"); + assert_eq!(*result[24], 145, "invalid result"); + assert_eq!(*result[25], 146, "invalid result"); + assert_eq!(*result[26], 83, "invalid result"); + assert_eq!(*result[27], 110, "invalid result"); + assert_eq!(*result[28], 185, "invalid result"); + assert_eq!(*result[29], 5, "invalid result"); + assert_eq!(*result[30], 248, "invalid result"); + assert_eq!(*result[31], 15, "invalid result"); } #[test] @@ -415,39 +415,39 @@ fn sha256_lorem_ipsum_test() { let result = sha256::sha256(input); // result should be 0xD35BF81DDF990122F8B96C7BF88C0737D5080E0C9BC3F7ABF68E6FF0D5F9EA44 - assert(result.len() == 32, 'invalid result length'); - assert(*result[0] == 0xD3, 'invalid result'); - assert(*result[1] == 0x5B, 'invalid result'); - assert(*result[2] == 0xF8, 'invalid result'); - assert(*result[3] == 0x1D, 'invalid result'); - assert(*result[4] == 0xDF, 'invalid result'); - assert(*result[5] == 0x99, 'invalid result'); - assert(*result[6] == 0x01, 'invalid result'); - assert(*result[7] == 0x22, 'invalid result'); - assert(*result[8] == 0xF8, 'invalid result'); - assert(*result[9] == 0xB9, 'invalid result'); - assert(*result[10] == 0x6C, 'invalid result'); - assert(*result[11] == 0x7B, 'invalid result'); - assert(*result[12] == 0xF8, 'invalid result'); - assert(*result[13] == 0x8C, 'invalid result'); - assert(*result[14] == 0x07, 'invalid result'); - assert(*result[15] == 0x37, 'invalid result'); - assert(*result[16] == 0xD5, 'invalid result'); - assert(*result[17] == 0x08, 'invalid result'); - assert(*result[18] == 0x0E, 'invalid result'); - assert(*result[19] == 0x0C, 'invalid result'); - assert(*result[20] == 0x9B, 'invalid result'); - assert(*result[21] == 0xC3, 'invalid result'); - assert(*result[22] == 0xF7, 'invalid result'); - assert(*result[23] == 0xAB, 'invalid result'); - assert(*result[24] == 0xF6, 'invalid result'); - assert(*result[25] == 0x8E, 'invalid result'); - assert(*result[26] == 0x6F, 'invalid result'); - assert(*result[27] == 0xF0, 'invalid result'); - assert(*result[28] == 0xD5, 'invalid result'); - assert(*result[29] == 0xF9, 'invalid result'); - assert(*result[30] == 0xEA, 'invalid result'); - assert(*result[31] == 0x44, 'invalid result'); + assert_eq!(result.len(), 32, "invalid result length"); + assert_eq!(*result[0], 0xD3, "invalid result"); + assert_eq!(*result[1], 0x5B, "invalid result"); + assert_eq!(*result[2], 0xF8, "invalid result"); + assert_eq!(*result[3], 0x1D, "invalid result"); + assert_eq!(*result[4], 0xDF, "invalid result"); + assert_eq!(*result[5], 0x99, "invalid result"); + assert_eq!(*result[6], 0x01, "invalid result"); + assert_eq!(*result[7], 0x22, "invalid result"); + assert_eq!(*result[8], 0xF8, "invalid result"); + assert_eq!(*result[9], 0xB9, "invalid result"); + assert_eq!(*result[10], 0x6C, "invalid result"); + assert_eq!(*result[11], 0x7B, "invalid result"); + assert_eq!(*result[12], 0xF8, "invalid result"); + assert_eq!(*result[13], 0x8C, "invalid result"); + assert_eq!(*result[14], 0x07, "invalid result"); + assert_eq!(*result[15], 0x37, "invalid result"); + assert_eq!(*result[16], 0xD5, "invalid result"); + assert_eq!(*result[17], 0x08, "invalid result"); + assert_eq!(*result[18], 0x0E, "invalid result"); + assert_eq!(*result[19], 0x0C, "invalid result"); + assert_eq!(*result[20], 0x9B, "invalid result"); + assert_eq!(*result[21], 0xC3, "invalid result"); + assert_eq!(*result[22], 0xF7, "invalid result"); + assert_eq!(*result[23], 0xAB, "invalid result"); + assert_eq!(*result[24], 0xF6, "invalid result"); + assert_eq!(*result[25], 0x8E, "invalid result"); + assert_eq!(*result[26], 0x6F, "invalid result"); + assert_eq!(*result[27], 0xF0, "invalid result"); + assert_eq!(*result[28], 0xD5, "invalid result"); + assert_eq!(*result[29], 0xF9, "invalid result"); + assert_eq!(*result[30], 0xEA, "invalid result"); + assert_eq!(*result[31], 0x44, "invalid result"); } #[test] #[available_gas(10_000_000_000)] @@ -665,37 +665,37 @@ fn sha256_url() { let result = sha256::sha256(data); // result should be 0xe5ddd0d703d54d024a1e49cdb614d1f4e9dfa81fff119ca01554ec22d1a45f59 - assert(result.len() == 32, 'invalid result length'); - assert(*result[0] == 0xE5, 'invalid result'); - assert(*result[1] == 0xDD, 'invalid result'); - assert(*result[2] == 0xD0, 'invalid result'); - assert(*result[3] == 0xD7, 'invalid result'); - assert(*result[4] == 0x03, 'invalid result'); - assert(*result[5] == 0xD5, 'invalid result'); - assert(*result[6] == 0x4D, 'invalid result'); - assert(*result[7] == 0x02, 'invalid result'); - assert(*result[8] == 0x4A, 'invalid result'); - assert(*result[9] == 0x1E, 'invalid result'); - assert(*result[10] == 0x49, 'invalid result'); - assert(*result[11] == 0xCD, 'invalid result'); - assert(*result[12] == 0xB6, 'invalid result'); - assert(*result[13] == 0x14, 'invalid result'); - assert(*result[14] == 0xD1, 'invalid result'); - assert(*result[15] == 0xF4, 'invalid result'); - assert(*result[16] == 0xE9, 'invalid result'); - assert(*result[17] == 0xDF, 'invalid result'); - assert(*result[18] == 0xA8, 'invalid result'); - assert(*result[19] == 0x1F, 'invalid result'); - assert(*result[20] == 0xFF, 'invalid result'); - assert(*result[21] == 0x11, 'invalid result'); - assert(*result[22] == 0x9C, 'invalid result'); - assert(*result[23] == 0xA0, 'invalid result'); - assert(*result[24] == 0x15, 'invalid result'); - assert(*result[25] == 0x54, 'invalid result'); - assert(*result[26] == 0xEC, 'invalid result'); - assert(*result[27] == 0x22, 'invalid result'); - assert(*result[28] == 0xD1, 'invalid result'); - assert(*result[29] == 0xA4, 'invalid result'); - assert(*result[30] == 0x5F, 'invalid result'); - assert(*result[31] == 0x59, 'invalid result'); + assert_eq!(result.len(), 32, "invalid result length"); + assert_eq!(*result[0], 0xE5, "invalid result"); + assert_eq!(*result[1], 0xDD, "invalid result"); + assert_eq!(*result[2], 0xD0, "invalid result"); + assert_eq!(*result[3], 0xD7, "invalid result"); + assert_eq!(*result[4], 0x03, "invalid result"); + assert_eq!(*result[5], 0xD5, "invalid result"); + assert_eq!(*result[6], 0x4D, "invalid result"); + assert_eq!(*result[7], 0x02, "invalid result"); + assert_eq!(*result[8], 0x4A, "invalid result"); + assert_eq!(*result[9], 0x1E, "invalid result"); + assert_eq!(*result[10], 0x49, "invalid result"); + assert_eq!(*result[11], 0xCD, "invalid result"); + assert_eq!(*result[12], 0xB6, "invalid result"); + assert_eq!(*result[13], 0x14, "invalid result"); + assert_eq!(*result[14], 0xD1, "invalid result"); + assert_eq!(*result[15], 0xF4, "invalid result"); + assert_eq!(*result[16], 0xE9, "invalid result"); + assert_eq!(*result[17], 0xDF, "invalid result"); + assert_eq!(*result[18], 0xA8, "invalid result"); + assert_eq!(*result[19], 0x1F, "invalid result"); + assert_eq!(*result[20], 0xFF, "invalid result"); + assert_eq!(*result[21], 0x11, "invalid result"); + assert_eq!(*result[22], 0x9C, "invalid result"); + assert_eq!(*result[23], 0xA0, "invalid result"); + assert_eq!(*result[24], 0x15, "invalid result"); + assert_eq!(*result[25], 0x54, "invalid result"); + assert_eq!(*result[26], 0xEC, "invalid result"); + assert_eq!(*result[27], 0x22, "invalid result"); + assert_eq!(*result[28], 0xD1, "invalid result"); + assert_eq!(*result[29], 0xA4, "invalid result"); + assert_eq!(*result[30], 0x5F, "invalid result"); + assert_eq!(*result[31], 0x59, "invalid result"); } diff --git a/src/math/src/tests/sha512_test.cairo b/src/math/src/tests/sha512_test.cairo index edf1537b..0c11c5ee 100644 --- a/src/math/src/tests/sha512_test.cairo +++ b/src/math/src/tests/sha512_test.cairo @@ -333,72 +333,72 @@ fn test_sha512_lorem_ipsum() { let msg = get_lorem_ipsum(); let res = sha512(msg); - assert(res.len() == 64, 'Incorrect hash length'); + assert_eq!(res.len(), 64, "Incorrect hash length"); - assert(*res[0] == 0xd5, 'Incorrect hash value'); - assert(*res[1] == 0xa2, 'Incorrect hash value'); - assert(*res[2] == 0xe1, 'Incorrect hash value'); - assert(*res[3] == 0x4e, 'Incorrect hash value'); - assert(*res[4] == 0xf4, 'Incorrect hash value'); - assert(*res[5] == 0x20, 'Incorrect hash value'); - assert(*res[6] == 0xf8, 'Incorrect hash value'); - assert(*res[7] == 0x2d, 'Incorrect hash value'); - assert(*res[8] == 0x68, 'Incorrect hash value'); - assert(*res[9] == 0x2b, 'Incorrect hash value'); - assert(*res[10] == 0x19, 'Incorrect hash value'); - assert(*res[11] == 0xc3, 'Incorrect hash value'); - assert(*res[12] == 0xd0, 'Incorrect hash value'); - assert(*res[13] == 0x70, 'Incorrect hash value'); - assert(*res[14] == 0xf4, 'Incorrect hash value'); - assert(*res[15] == 0x81, 'Incorrect hash value'); - assert(*res[16] == 0x14, 'Incorrect hash value'); - assert(*res[17] == 0xcb, 'Incorrect hash value'); - assert(*res[18] == 0xb9, 'Incorrect hash value'); - assert(*res[19] == 0x74, 'Incorrect hash value'); - assert(*res[20] == 0x7c, 'Incorrect hash value'); - assert(*res[21] == 0x7d, 'Incorrect hash value'); - assert(*res[22] == 0xb1, 'Incorrect hash value'); - assert(*res[23] == 0x15, 'Incorrect hash value'); - assert(*res[24] == 0xce, 'Incorrect hash value'); - assert(*res[25] == 0xa5, 'Incorrect hash value'); - assert(*res[26] == 0x41, 'Incorrect hash value'); - assert(*res[27] == 0x3e, 'Incorrect hash value'); - assert(*res[28] == 0xf8, 'Incorrect hash value'); - assert(*res[29] == 0xcb, 'Incorrect hash value'); - assert(*res[30] == 0x8f, 'Incorrect hash value'); - assert(*res[31] == 0xba, 'Incorrect hash value'); - assert(*res[32] == 0xc6, 'Incorrect hash value'); - assert(*res[33] == 0x90, 'Incorrect hash value'); - assert(*res[34] == 0x17, 'Incorrect hash value'); - assert(*res[35] == 0xc5, 'Incorrect hash value'); - assert(*res[36] == 0x17, 'Incorrect hash value'); - assert(*res[37] == 0x0f, 'Incorrect hash value'); - assert(*res[38] == 0x01, 'Incorrect hash value'); - assert(*res[39] == 0xc4, 'Incorrect hash value'); - assert(*res[40] == 0x77, 'Incorrect hash value'); - assert(*res[41] == 0xb3, 'Incorrect hash value'); - assert(*res[42] == 0xdf, 'Incorrect hash value'); - assert(*res[43] == 0x3d, 'Incorrect hash value'); - assert(*res[44] == 0xfb, 'Incorrect hash value'); - assert(*res[45] == 0x34, 'Incorrect hash value'); - assert(*res[46] == 0xd3, 'Incorrect hash value'); - assert(*res[47] == 0x50, 'Incorrect hash value'); - assert(*res[48] == 0x8f, 'Incorrect hash value'); - assert(*res[49] == 0xa0, 'Incorrect hash value'); - assert(*res[50] == 0xb2, 'Incorrect hash value'); - assert(*res[51] == 0xb1, 'Incorrect hash value'); - assert(*res[52] == 0x37, 'Incorrect hash value'); - assert(*res[53] == 0xd4, 'Incorrect hash value'); - assert(*res[54] == 0xcb, 'Incorrect hash value'); - assert(*res[55] == 0x54, 'Incorrect hash value'); - assert(*res[56] == 0x60, 'Incorrect hash value'); - assert(*res[57] == 0x9e, 'Incorrect hash value'); - assert(*res[58] == 0x63, 'Incorrect hash value'); - assert(*res[59] == 0x3d, 'Incorrect hash value'); - assert(*res[60] == 0x14, 'Incorrect hash value'); - assert(*res[61] == 0x45, 'Incorrect hash value'); - assert(*res[62] == 0x82, 'Incorrect hash value'); - assert(*res[63] == 0xc9, 'Incorrect hash value'); + assert_eq!(*res[0], 0xd5, "Incorrect hash value"); + assert_eq!(*res[1], 0xa2, "Incorrect hash value"); + assert_eq!(*res[2], 0xe1, "Incorrect hash value"); + assert_eq!(*res[3], 0x4e, "Incorrect hash value"); + assert_eq!(*res[4], 0xf4, "Incorrect hash value"); + assert_eq!(*res[5], 0x20, "Incorrect hash value"); + assert_eq!(*res[6], 0xf8, "Incorrect hash value"); + assert_eq!(*res[7], 0x2d, "Incorrect hash value"); + assert_eq!(*res[8], 0x68, "Incorrect hash value"); + assert_eq!(*res[9], 0x2b, "Incorrect hash value"); + assert_eq!(*res[10], 0x19, "Incorrect hash value"); + assert_eq!(*res[11], 0xc3, "Incorrect hash value"); + assert_eq!(*res[12], 0xd0, "Incorrect hash value"); + assert_eq!(*res[13], 0x70, "Incorrect hash value"); + assert_eq!(*res[14], 0xf4, "Incorrect hash value"); + assert_eq!(*res[15], 0x81, "Incorrect hash value"); + assert_eq!(*res[16], 0x14, "Incorrect hash value"); + assert_eq!(*res[17], 0xcb, "Incorrect hash value"); + assert_eq!(*res[18], 0xb9, "Incorrect hash value"); + assert_eq!(*res[19], 0x74, "Incorrect hash value"); + assert_eq!(*res[20], 0x7c, "Incorrect hash value"); + assert_eq!(*res[21], 0x7d, "Incorrect hash value"); + assert_eq!(*res[22], 0xb1, "Incorrect hash value"); + assert_eq!(*res[23], 0x15, "Incorrect hash value"); + assert_eq!(*res[24], 0xce, "Incorrect hash value"); + assert_eq!(*res[25], 0xa5, "Incorrect hash value"); + assert_eq!(*res[26], 0x41, "Incorrect hash value"); + assert_eq!(*res[27], 0x3e, "Incorrect hash value"); + assert_eq!(*res[28], 0xf8, "Incorrect hash value"); + assert_eq!(*res[29], 0xcb, "Incorrect hash value"); + assert_eq!(*res[30], 0x8f, "Incorrect hash value"); + assert_eq!(*res[31], 0xba, "Incorrect hash value"); + assert_eq!(*res[32], 0xc6, "Incorrect hash value"); + assert_eq!(*res[33], 0x90, "Incorrect hash value"); + assert_eq!(*res[34], 0x17, "Incorrect hash value"); + assert_eq!(*res[35], 0xc5, "Incorrect hash value"); + assert_eq!(*res[36], 0x17, "Incorrect hash value"); + assert_eq!(*res[37], 0x0f, "Incorrect hash value"); + assert_eq!(*res[38], 0x01, "Incorrect hash value"); + assert_eq!(*res[39], 0xc4, "Incorrect hash value"); + assert_eq!(*res[40], 0x77, "Incorrect hash value"); + assert_eq!(*res[41], 0xb3, "Incorrect hash value"); + assert_eq!(*res[42], 0xdf, "Incorrect hash value"); + assert_eq!(*res[43], 0x3d, "Incorrect hash value"); + assert_eq!(*res[44], 0xfb, "Incorrect hash value"); + assert_eq!(*res[45], 0x34, "Incorrect hash value"); + assert_eq!(*res[46], 0xd3, "Incorrect hash value"); + assert_eq!(*res[47], 0x50, "Incorrect hash value"); + assert_eq!(*res[48], 0x8f, "Incorrect hash value"); + assert_eq!(*res[49], 0xa0, "Incorrect hash value"); + assert_eq!(*res[50], 0xb2, "Incorrect hash value"); + assert_eq!(*res[51], 0xb1, "Incorrect hash value"); + assert_eq!(*res[52], 0x37, "Incorrect hash value"); + assert_eq!(*res[53], 0xd4, "Incorrect hash value"); + assert_eq!(*res[54], 0xcb, "Incorrect hash value"); + assert_eq!(*res[55], 0x54, "Incorrect hash value"); + assert_eq!(*res[56], 0x60, "Incorrect hash value"); + assert_eq!(*res[57], 0x9e, "Incorrect hash value"); + assert_eq!(*res[58], 0x63, "Incorrect hash value"); + assert_eq!(*res[59], 0x3d, "Incorrect hash value"); + assert_eq!(*res[60], 0x14, "Incorrect hash value"); + assert_eq!(*res[61], 0x45, "Incorrect hash value"); + assert_eq!(*res[62], 0x82, "Incorrect hash value"); + assert_eq!(*res[63], 0xc9, "Incorrect hash value"); } #[test] @@ -407,72 +407,72 @@ fn test_sha512_size_one() { let mut arr: Array = array![49]; let mut res = sha512(arr); - assert(res.len() == 64, 'Len should be 64'); + assert_eq!(res.len(), 64, "Len should be 64"); - assert(*res[0] == 0x4d, 'invalid value for hash'); - assert(*res[1] == 0xff, 'invalid value for hash'); - assert(*res[2] == 0x4e, 'invalid value for hash'); - assert(*res[3] == 0xa3, 'invalid value for hash'); - assert(*res[4] == 0x40, 'invalid value for hash'); - assert(*res[5] == 0xf0, 'invalid value for hash'); - assert(*res[6] == 0xa8, 'invalid value for hash'); - assert(*res[7] == 0x23, 'invalid value for hash'); - assert(*res[8] == 0xf1, 'invalid value for hash'); - assert(*res[9] == 0x5d, 'invalid value for hash'); - assert(*res[10] == 0x3f, 'invalid value for hash'); - assert(*res[11] == 0x4f, 'invalid value for hash'); - assert(*res[12] == 0x01, 'invalid value for hash'); - assert(*res[13] == 0xab, 'invalid value for hash'); - assert(*res[14] == 0x62, 'invalid value for hash'); - assert(*res[15] == 0xea, 'invalid value for hash'); - assert(*res[16] == 0xe0, 'invalid value for hash'); - assert(*res[17] == 0xe5, 'invalid value for hash'); - assert(*res[18] == 0xda, 'invalid value for hash'); - assert(*res[19] == 0x57, 'invalid value for hash'); - assert(*res[20] == 0x9c, 'invalid value for hash'); - assert(*res[21] == 0xcb, 'invalid value for hash'); - assert(*res[22] == 0x85, 'invalid value for hash'); - assert(*res[23] == 0x1f, 'invalid value for hash'); - assert(*res[24] == 0x8d, 'invalid value for hash'); - assert(*res[25] == 0xb9, 'invalid value for hash'); - assert(*res[26] == 0xdf, 'invalid value for hash'); - assert(*res[27] == 0xe8, 'invalid value for hash'); - assert(*res[28] == 0x4c, 'invalid value for hash'); - assert(*res[29] == 0x58, 'invalid value for hash'); - assert(*res[30] == 0xb2, 'invalid value for hash'); - assert(*res[31] == 0xb3, 'invalid value for hash'); - assert(*res[32] == 0x7b, 'invalid value for hash'); - assert(*res[33] == 0x89, 'invalid value for hash'); - assert(*res[34] == 0x90, 'invalid value for hash'); - assert(*res[35] == 0x3a, 'invalid value for hash'); - assert(*res[36] == 0x74, 'invalid value for hash'); - assert(*res[37] == 0x0e, 'invalid value for hash'); - assert(*res[38] == 0x1e, 'invalid value for hash'); - assert(*res[39] == 0xe1, 'invalid value for hash'); - assert(*res[40] == 0x72, 'invalid value for hash'); - assert(*res[41] == 0xda, 'invalid value for hash'); - assert(*res[42] == 0x79, 'invalid value for hash'); - assert(*res[43] == 0x3a, 'invalid value for hash'); - assert(*res[44] == 0x6e, 'invalid value for hash'); - assert(*res[45] == 0x79, 'invalid value for hash'); - assert(*res[46] == 0xd5, 'invalid value for hash'); - assert(*res[47] == 0x60, 'invalid value for hash'); - assert(*res[48] == 0xe5, 'invalid value for hash'); - assert(*res[49] == 0xf7, 'invalid value for hash'); - assert(*res[50] == 0xf9, 'invalid value for hash'); - assert(*res[51] == 0xbd, 'invalid value for hash'); - assert(*res[52] == 0x05, 'invalid value for hash'); - assert(*res[53] == 0x8a, 'invalid value for hash'); - assert(*res[54] == 0x12, 'invalid value for hash'); - assert(*res[55] == 0xa2, 'invalid value for hash'); - assert(*res[56] == 0x80, 'invalid value for hash'); - assert(*res[57] == 0x43, 'invalid value for hash'); - assert(*res[58] == 0x3e, 'invalid value for hash'); - assert(*res[59] == 0xd6, 'invalid value for hash'); - assert(*res[60] == 0xfa, 'invalid value for hash'); - assert(*res[61] == 0x46, 'invalid value for hash'); - assert(*res[62] == 0x51, 'invalid value for hash'); - assert(*res[63] == 0x0a, 'invalid value for hash'); + assert_eq!(*res[0], 0x4d, "invalid value for hash"); + assert_eq!(*res[1], 0xff, "invalid value for hash"); + assert_eq!(*res[2], 0x4e, "invalid value for hash"); + assert_eq!(*res[3], 0xa3, "invalid value for hash"); + assert_eq!(*res[4], 0x40, "invalid value for hash"); + assert_eq!(*res[5], 0xf0, "invalid value for hash"); + assert_eq!(*res[6], 0xa8, "invalid value for hash"); + assert_eq!(*res[7], 0x23, "invalid value for hash"); + assert_eq!(*res[8], 0xf1, "invalid value for hash"); + assert_eq!(*res[9], 0x5d, "invalid value for hash"); + assert_eq!(*res[10], 0x3f, "invalid value for hash"); + assert_eq!(*res[11], 0x4f, "invalid value for hash"); + assert_eq!(*res[12], 0x01, "invalid value for hash"); + assert_eq!(*res[13], 0xab, "invalid value for hash"); + assert_eq!(*res[14], 0x62, "invalid value for hash"); + assert_eq!(*res[15], 0xea, "invalid value for hash"); + assert_eq!(*res[16], 0xe0, "invalid value for hash"); + assert_eq!(*res[17], 0xe5, "invalid value for hash"); + assert_eq!(*res[18], 0xda, "invalid value for hash"); + assert_eq!(*res[19], 0x57, "invalid value for hash"); + assert_eq!(*res[20], 0x9c, "invalid value for hash"); + assert_eq!(*res[21], 0xcb, "invalid value for hash"); + assert_eq!(*res[22], 0x85, "invalid value for hash"); + assert_eq!(*res[23], 0x1f, "invalid value for hash"); + assert_eq!(*res[24], 0x8d, "invalid value for hash"); + assert_eq!(*res[25], 0xb9, "invalid value for hash"); + assert_eq!(*res[26], 0xdf, "invalid value for hash"); + assert_eq!(*res[27], 0xe8, "invalid value for hash"); + assert_eq!(*res[28], 0x4c, "invalid value for hash"); + assert_eq!(*res[29], 0x58, "invalid value for hash"); + assert_eq!(*res[30], 0xb2, "invalid value for hash"); + assert_eq!(*res[31], 0xb3, "invalid value for hash"); + assert_eq!(*res[32], 0x7b, "invalid value for hash"); + assert_eq!(*res[33], 0x89, "invalid value for hash"); + assert_eq!(*res[34], 0x90, "invalid value for hash"); + assert_eq!(*res[35], 0x3a, "invalid value for hash"); + assert_eq!(*res[36], 0x74, "invalid value for hash"); + assert_eq!(*res[37], 0x0e, "invalid value for hash"); + assert_eq!(*res[38], 0x1e, "invalid value for hash"); + assert_eq!(*res[39], 0xe1, "invalid value for hash"); + assert_eq!(*res[40], 0x72, "invalid value for hash"); + assert_eq!(*res[41], 0xda, "invalid value for hash"); + assert_eq!(*res[42], 0x79, "invalid value for hash"); + assert_eq!(*res[43], 0x3a, "invalid value for hash"); + assert_eq!(*res[44], 0x6e, "invalid value for hash"); + assert_eq!(*res[45], 0x79, "invalid value for hash"); + assert_eq!(*res[46], 0xd5, "invalid value for hash"); + assert_eq!(*res[47], 0x60, "invalid value for hash"); + assert_eq!(*res[48], 0xe5, "invalid value for hash"); + assert_eq!(*res[49], 0xf7, "invalid value for hash"); + assert_eq!(*res[50], 0xf9, "invalid value for hash"); + assert_eq!(*res[51], 0xbd, "invalid value for hash"); + assert_eq!(*res[52], 0x05, "invalid value for hash"); + assert_eq!(*res[53], 0x8a, "invalid value for hash"); + assert_eq!(*res[54], 0x12, "invalid value for hash"); + assert_eq!(*res[55], 0xa2, "invalid value for hash"); + assert_eq!(*res[56], 0x80, "invalid value for hash"); + assert_eq!(*res[57], 0x43, "invalid value for hash"); + assert_eq!(*res[58], 0x3e, "invalid value for hash"); + assert_eq!(*res[59], 0xd6, "invalid value for hash"); + assert_eq!(*res[60], 0xfa, "invalid value for hash"); + assert_eq!(*res[61], 0x46, "invalid value for hash"); + assert_eq!(*res[62], 0x51, "invalid value for hash"); + assert_eq!(*res[63], 0x0a, "invalid value for hash"); } #[test] @@ -482,69 +482,69 @@ fn test_size_zero() { let res = sha512(msg); - assert(res.len() == 64, 'Incorrect hash len'); - assert(*res[0] == 0xcf, 'Incorrect hash len'); - assert(*res[1] == 0x83, 'Incorrect hash len'); - assert(*res[2] == 0xe1, 'Incorrect hash len'); - assert(*res[3] == 0x35, 'Incorrect hash len'); - assert(*res[4] == 0x7e, 'Incorrect hash len'); - assert(*res[5] == 0xef, 'Incorrect hash len'); - assert(*res[6] == 0xb8, 'Incorrect hash len'); - assert(*res[7] == 0xbd, 'Incorrect hash len'); - assert(*res[8] == 0xf1, 'Incorrect hash len'); - assert(*res[9] == 0x54, 'Incorrect hash len'); - assert(*res[10] == 0x28, 'Incorrect hash len'); - assert(*res[11] == 0x50, 'Incorrect hash len'); - assert(*res[12] == 0xd6, 'Incorrect hash len'); - assert(*res[13] == 0x6d, 'Incorrect hash len'); - assert(*res[14] == 0x80, 'Incorrect hash len'); - assert(*res[15] == 0x07, 'Incorrect hash len'); - assert(*res[16] == 0xd6, 'Incorrect hash len'); - assert(*res[17] == 0x20, 'Incorrect hash len'); - assert(*res[18] == 0xe4, 'Incorrect hash len'); - assert(*res[19] == 0x05, 'Incorrect hash len'); - assert(*res[20] == 0x0b, 'Incorrect hash len'); - assert(*res[21] == 0x57, 'Incorrect hash len'); - assert(*res[22] == 0x15, 'Incorrect hash len'); - assert(*res[23] == 0xdc, 'Incorrect hash len'); - assert(*res[24] == 0x83, 'Incorrect hash len'); - assert(*res[25] == 0xf4, 'Incorrect hash len'); - assert(*res[26] == 0xa9, 'Incorrect hash len'); - assert(*res[27] == 0x21, 'Incorrect hash len'); - assert(*res[28] == 0xd3, 'Incorrect hash len'); - assert(*res[29] == 0x6c, 'Incorrect hash len'); - assert(*res[30] == 0xe9, 'Incorrect hash len'); - assert(*res[31] == 0xce, 'Incorrect hash len'); - assert(*res[32] == 0x47, 'Incorrect hash len'); - assert(*res[33] == 0xd0, 'Incorrect hash len'); - assert(*res[34] == 0xd1, 'Incorrect hash len'); - assert(*res[35] == 0x3c, 'Incorrect hash len'); - assert(*res[36] == 0x5d, 'Incorrect hash len'); - assert(*res[37] == 0x85, 'Incorrect hash len'); - assert(*res[38] == 0xf2, 'Incorrect hash len'); - assert(*res[39] == 0xb0, 'Incorrect hash len'); - assert(*res[40] == 0xff, 'Incorrect hash len'); - assert(*res[41] == 0x83, 'Incorrect hash len'); - assert(*res[42] == 0x18, 'Incorrect hash len'); - assert(*res[43] == 0xd2, 'Incorrect hash len'); - assert(*res[44] == 0x87, 'Incorrect hash len'); - assert(*res[45] == 0x7e, 'Incorrect hash len'); - assert(*res[46] == 0xec, 'Incorrect hash len'); - assert(*res[47] == 0x2f, 'Incorrect hash len'); - assert(*res[48] == 0x63, 'Incorrect hash len'); - assert(*res[49] == 0xb9, 'Incorrect hash len'); - assert(*res[50] == 0x31, 'Incorrect hash len'); - assert(*res[51] == 0xbd, 'Incorrect hash len'); - assert(*res[52] == 0x47, 'Incorrect hash len'); - assert(*res[53] == 0x41, 'Incorrect hash len'); - assert(*res[54] == 0x7a, 'Incorrect hash len'); - assert(*res[55] == 0x81, 'Incorrect hash len'); - assert(*res[56] == 0xa5, 'Incorrect hash len'); - assert(*res[57] == 0x38, 'Incorrect hash len'); - assert(*res[58] == 0x32, 'Incorrect hash len'); - assert(*res[59] == 0x7a, 'Incorrect hash len'); - assert(*res[60] == 0xf9, 'Incorrect hash len'); - assert(*res[61] == 0x27, 'Incorrect hash len'); - assert(*res[62] == 0xda, 'Incorrect hash len'); - assert(*res[63] == 0x3e, 'Incorrect hash len'); + assert_eq!(res.len(), 64, "Incorrect hash len"); + assert_eq!(*res[0], 0xcf, "Incorrect hash len"); + assert_eq!(*res[1], 0x83, "Incorrect hash len"); + assert_eq!(*res[2], 0xe1, "Incorrect hash len"); + assert_eq!(*res[3], 0x35, "Incorrect hash len"); + assert_eq!(*res[4], 0x7e, "Incorrect hash len"); + assert_eq!(*res[5], 0xef, "Incorrect hash len"); + assert_eq!(*res[6], 0xb8, "Incorrect hash len"); + assert_eq!(*res[7], 0xbd, "Incorrect hash len"); + assert_eq!(*res[8], 0xf1, "Incorrect hash len"); + assert_eq!(*res[9], 0x54, "Incorrect hash len"); + assert_eq!(*res[10], 0x28, "Incorrect hash len"); + assert_eq!(*res[11], 0x50, "Incorrect hash len"); + assert_eq!(*res[12], 0xd6, "Incorrect hash len"); + assert_eq!(*res[13], 0x6d, "Incorrect hash len"); + assert_eq!(*res[14], 0x80, "Incorrect hash len"); + assert_eq!(*res[15], 0x07, "Incorrect hash len"); + assert_eq!(*res[16], 0xd6, "Incorrect hash len"); + assert_eq!(*res[17], 0x20, "Incorrect hash len"); + assert_eq!(*res[18], 0xe4, "Incorrect hash len"); + assert_eq!(*res[19], 0x05, "Incorrect hash len"); + assert_eq!(*res[20], 0x0b, "Incorrect hash len"); + assert_eq!(*res[21], 0x57, "Incorrect hash len"); + assert_eq!(*res[22], 0x15, "Incorrect hash len"); + assert_eq!(*res[23], 0xdc, "Incorrect hash len"); + assert_eq!(*res[24], 0x83, "Incorrect hash len"); + assert_eq!(*res[25], 0xf4, "Incorrect hash len"); + assert_eq!(*res[26], 0xa9, "Incorrect hash len"); + assert_eq!(*res[27], 0x21, "Incorrect hash len"); + assert_eq!(*res[28], 0xd3, "Incorrect hash len"); + assert_eq!(*res[29], 0x6c, "Incorrect hash len"); + assert_eq!(*res[30], 0xe9, "Incorrect hash len"); + assert_eq!(*res[31], 0xce, "Incorrect hash len"); + assert_eq!(*res[32], 0x47, "Incorrect hash len"); + assert_eq!(*res[33], 0xd0, "Incorrect hash len"); + assert_eq!(*res[34], 0xd1, "Incorrect hash len"); + assert_eq!(*res[35], 0x3c, "Incorrect hash len"); + assert_eq!(*res[36], 0x5d, "Incorrect hash len"); + assert_eq!(*res[37], 0x85, "Incorrect hash len"); + assert_eq!(*res[38], 0xf2, "Incorrect hash len"); + assert_eq!(*res[39], 0xb0, "Incorrect hash len"); + assert_eq!(*res[40], 0xff, "Incorrect hash len"); + assert_eq!(*res[41], 0x83, "Incorrect hash len"); + assert_eq!(*res[42], 0x18, "Incorrect hash len"); + assert_eq!(*res[43], 0xd2, "Incorrect hash len"); + assert_eq!(*res[44], 0x87, "Incorrect hash len"); + assert_eq!(*res[45], 0x7e, "Incorrect hash len"); + assert_eq!(*res[46], 0xec, "Incorrect hash len"); + assert_eq!(*res[47], 0x2f, "Incorrect hash len"); + assert_eq!(*res[48], 0x63, "Incorrect hash len"); + assert_eq!(*res[49], 0xb9, "Incorrect hash len"); + assert_eq!(*res[50], 0x31, "Incorrect hash len"); + assert_eq!(*res[51], 0xbd, "Incorrect hash len"); + assert_eq!(*res[52], 0x47, "Incorrect hash len"); + assert_eq!(*res[53], 0x41, "Incorrect hash len"); + assert_eq!(*res[54], 0x7a, "Incorrect hash len"); + assert_eq!(*res[55], 0x81, "Incorrect hash len"); + assert_eq!(*res[56], 0xa5, "Incorrect hash len"); + assert_eq!(*res[57], 0x38, "Incorrect hash len"); + assert_eq!(*res[58], 0x32, "Incorrect hash len"); + assert_eq!(*res[59], 0x7a, "Incorrect hash len"); + assert_eq!(*res[60], 0xf9, "Incorrect hash len"); + assert_eq!(*res[61], 0x27, "Incorrect hash len"); + assert_eq!(*res[62], 0xda, "Incorrect hash len"); + assert_eq!(*res[63], 0x3e, "Incorrect hash len"); } diff --git a/src/math/src/tests/test_keccak256.cairo b/src/math/src/tests/test_keccak256.cairo index 5c839d7f..57f1db60 100644 --- a/src/math/src/tests/test_keccak256.cairo +++ b/src/math/src/tests/test_keccak256.cairo @@ -6,11 +6,9 @@ fn test_keccak256_empty_bytes() { let input = array![]; let hash = keccak256(input.span()); + let expected = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; - assert( - hash == 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470, - 'wrong hash value' - ) + assert(hash == expected, 'wrong hash value') } #[test] @@ -19,11 +17,9 @@ fn test_keccak256_partial_bytes() { let input = array![0x00, 0x01, 0x02, 0x03, 0x04, 0x05]; let hash = keccak256(input.span()); + let expected = 0x51e8babe8b42352100dffa7f7b3843c95245d3d545c6cbf5052e80258ae80627; - assert( - hash == 0x51e8babe8b42352100dffa7f7b3843c95245d3d545c6cbf5052e80258ae80627, - 'wrong hash value' - ); + assert(hash == expected, 'wrong hash value'); } #[test] @@ -66,9 +62,7 @@ fn test_keccak256_full_u256() { ]; let hash = keccak256(input.span()); + let expected = 0x98cfb1eca8a71b4a4b1c115f3d5a462296a66487d1d97fb4c47b979c64bde069; - assert( - hash == 0x98cfb1eca8a71b4a4b1c115f3d5a462296a66487d1d97fb4c47b979c64bde069, - 'wrong hash value' - ); + assert(hash == expected, 'wrong hash value'); } diff --git a/src/math/src/tests/trigonometry_test.cairo b/src/math/src/tests/trigonometry_test.cairo index 17ae83f7..e7be1301 100644 --- a/src/math/src/tests/trigonometry_test.cairo +++ b/src/math/src/tests/trigonometry_test.cairo @@ -5,53 +5,53 @@ use alexandria_math::trigonometry::fast_tan; #[test] #[available_gas(200000)] fn sin_positive_test_1() { - assert(fast_sin(3000000000) == 50000000, 'invalid result'); + assert!(fast_sin(3000000000) == 50000000, "invalid result"); } #[test] #[available_gas(200000)] fn sin_negative_test_1() { - assert(fast_sin(21000000000) == -50000000, 'invalid result'); + assert!(fast_sin(21000000000) == -50000000, "invalid result"); } #[test] #[available_gas(200000)] fn sin_positive_test_2() { - assert(fast_sin(3500000000) == 57367231, 'invalid result'); + assert!(fast_sin(3500000000) == 57367231, "invalid result"); } #[test] #[available_gas(200000)] fn sin_negative_test_2() { - assert(fast_sin(24300000000) == -89101846, 'invalid result'); + assert!(fast_sin(24300000000) == -89101846, "invalid result"); } #[test] #[available_gas(200000)] fn sin_positive_test_3() { - assert(fast_sin(75000000000) == 50000000, 'invalid result'); + assert!(fast_sin(75000000000) == 50000000, "invalid result"); } #[test] #[available_gas(200000)] fn cos_positive_test_1() { - assert(fast_cos(6000000000) == 50000000, 'invalid result'); + assert!(fast_cos(6000000000) == 50000000, "invalid result"); } #[test] #[available_gas(200000)] fn cos_negative_test_1() { - assert(fast_cos(12000000000) == -50000000, 'invalid result'); + assert!(fast_cos(12000000000) == -50000000, "invalid result"); } #[test] #[available_gas(200000)] fn tan_positive_test_1() { - assert(fast_tan(4500000000) == 100000000, 'invalid result'); + assert!(fast_tan(4500000000) == 100000000, "invalid result"); } #[test] #[available_gas(200000)] fn tan_negative_test_1() { - assert(fast_tan(-4500000000) == -100000000, 'invalid result'); + assert!(fast_tan(-4500000000) == -100000000, "invalid result"); } diff --git a/src/math/src/tests/wad_ray_math_test.cairo b/src/math/src/tests/wad_ray_math_test.cairo index d96e3ab3..9ae466a2 100644 --- a/src/math/src/tests/wad_ray_math_test.cairo +++ b/src/math/src/tests/wad_ray_math_test.cairo @@ -9,7 +9,7 @@ use alexandria_math::{pow}; fn test_wad_to_ray_conversion() { let a = 5 * pow(10, 17); // 0.5e18 let expected = 5 * pow(10, 26); // 0.5e27 - assert(wad_to_ray(a) == expected, 'Wrong wad_to_ray conversion'); + assert_eq!(wad_to_ray(a), expected, "Wrong wad_to_ray conversion"); } #[test] @@ -17,7 +17,7 @@ fn test_wad_to_ray_conversion() { fn test_ray_to_wad_conversion() { let a = 5 * pow(10, 26); // 0.5e27 let expected = 5 * pow(10, 17); // 0.5e18 - assert(ray_to_wad(a) == expected, 'Wrong ray_to_wad conversion'); + assert_eq!(ray_to_wad(a), expected, "Wrong ray_to_wad conversion"); } // wad @@ -31,19 +31,19 @@ fn test_revertWhen_wad_mul_overflow() { #[test] #[available_gas(2000000)] fn test_wad_mul_trivial() { - assert(wad_mul(pow(2, 128) - 1, wad()) == pow(2, 128) - 1, 'Wrong result: 2**128 -1 * 1e18'); - assert(wad_mul(0, 0) == 0, 'Wrong result: 0 * 0'); - assert(wad_mul(0, wad()) == 0, 'Wrong result: 0 * 1e18'); - assert(wad_mul(wad(), 0) == 0, 'Wrong result: 1e18 * 0'); - assert(wad_mul(wad(), wad()) == wad(), 'Wrong result: 1e18 * 1e18 '); + assert_eq!(wad_mul(pow(2, 128) - 1, wad()), pow(2, 128) - 1, "Wrong result: 2**128 -1 * 1e18"); + assert_eq!(wad_mul(0, 0), 0, "Wrong result: 0 * 0"); + assert_eq!(wad_mul(0, wad()), 0, "Wrong result: 0 * 1e18"); + assert_eq!(wad_mul(wad(), 0), 0, "Wrong result: 1e18 * 0"); + assert_eq!(wad_mul(wad(), wad()), wad(), "Wrong result: 1e18 * 1e18 "); } #[test] #[available_gas(2000000)] fn test_wad_mul_fractions() { let val: u256 = 2 * pow(10, 17); // 0.2e18 - assert(wad_mul(wad(), val) == val, 'Wrong result: 1e18 * 0.2e18'); - assert(wad_mul(wad() * 2, val) == val * 2, 'Wrong result: 2e18 * 0.2e18'); + assert_eq!(wad_mul(wad(), val), val, "Wrong result: 1e18 * 0.2e18"); + assert_eq!(wad_mul(wad() * 2, val), val * 2, "Wrong result: 2e18 * 0.2e18"); } #[test] @@ -56,16 +56,16 @@ fn test_revertWhen_wad_div_zero() { #[test] #[available_gas(3000000)] fn test_wad_div_trivial() { - assert(wad_div(pow(2, 128) - 1, wad()) == pow(2, 128) - 1, 'Wrong result: 2**128 -1 / 1e18'); - assert(wad_div(0, pow(2, 128) - 1) == 0, 'Wrong result: 0 / 2**128 -1'); - assert(wad_div(wad(), wad()) == wad(), 'Wrong result: 1e18 / 1e18'); + assert_eq!(wad_div(pow(2, 128) - 1, wad()), pow(2, 128) - 1, "Wrong result: 2**128 -1 / 1e18"); + assert_eq!(wad_div(0, pow(2, 128) - 1), 0, "Wrong result: 0 / 2**128 -1"); + assert_eq!(wad_div(wad(), wad()), wad(), "Wrong result: 1e18 / 1e18"); } #[test] #[available_gas(2000000)] fn test_wad_div_fractions() { - assert(wad_div(wad() * 2, wad() * 2) == wad(), 'Wrong result: 2e18 / 2e18'); - assert(wad_div(wad(), wad() * 2) == half_wad(), 'Wrong result: 1e18 / 2e18'); + assert_eq!(wad_div(wad() * 2, wad() * 2), wad(), "Wrong result: 2e18 / 2e18"); + assert_eq!(wad_div(wad(), wad() * 2), half_wad(), "Wrong result: 1e18 / 2e18"); } #[test] @@ -74,8 +74,8 @@ fn test_wad_mul_rounding() { let a = 950000000000005647; let b = 1000000000; let expected = 950000000; - assert(wad_mul(a, b) == expected, 'Wrong rounding down: a * b'); - assert(wad_mul(b, a) == expected, 'Wrong rounding down: b * a'); + assert_eq!(wad_mul(a, b), expected, "Wrong rounding down: a * b"); + assert_eq!(wad_mul(b, a), expected, "Wrong rounding down: b * a"); } #[test] @@ -84,8 +84,8 @@ fn test_wad_mul_rounding_up() { let a = pow(10, 18) - 1; let b = 2; let expected = 2; - assert(wad_mul(a, b) == expected, 'Wrong rounding: a * b'); - assert(wad_mul(b, a) == expected, 'Wrong rounding: b * a'); + assert_eq!(wad_mul(a, b), expected, "Wrong rounding: a * b"); + assert_eq!(wad_mul(b, a), expected, "Wrong rounding: b * a"); } @@ -100,19 +100,19 @@ fn test_revertWhen_ray_mul_overflow() { #[test] #[available_gas(2000000)] fn test_ray_mul_trivial() { - assert(ray_mul(pow(2, 128) - 1, ray()) == pow(2, 128) - 1, 'Wrong result: 2**128 -1 * 1e27'); - assert(ray_mul(0, 0) == 0, 'Wrong result: 0 * 0'); - assert(ray_mul(0, ray()) == 0, 'Wrong result: 0 * 1e27'); - assert(ray_mul(ray(), 0) == 0, 'Wrong result: 1e27 * 0'); - assert(ray_mul(ray(), ray()) == ray(), 'Wrong result: 1e27 * 1e27 '); + assert_eq!(ray_mul(pow(2, 128) - 1, ray()), pow(2, 128) - 1, "Wrong result: 2**128 -1 * 1e27"); + assert_eq!(ray_mul(0, 0), 0, "Wrong result: 0 * 0"); + assert_eq!(ray_mul(0, ray()), 0, "Wrong result: 0 * 1e27"); + assert_eq!(ray_mul(ray(), 0), 0, "Wrong result: 1e27 * 0"); + assert_eq!(ray_mul(ray(), ray()), ray(), "Wrong result: 1e27 * 1e27 "); } #[test] #[available_gas(2000000)] fn test_ray_mul_fractions() { let val: u256 = 2 * pow(10, 26); // 0.2e27 - assert(ray_mul(ray(), val) == val, 'Wrong result: 1e27 * 0.2e27'); - assert(ray_mul(ray() * 2, val) == val * 2, 'Wrong result: 2e27 * 0.2e27'); + assert_eq!(ray_mul(ray(), val), val, "Wrong result: 1e27 * 0.2e27"); + assert_eq!(ray_mul(ray() * 2, val), val * 2, "Wrong result: 2e27 * 0.2e27"); } #[test] @@ -125,16 +125,16 @@ fn test_revertWhen_ray_div_zero() { #[test] #[available_gas(3000000)] fn test_ray_div_trivial() { - assert(ray_div(pow(2, 128) - 1, ray()) == pow(2, 128) - 1, 'Wrong result: 2**128 -1 / 1e27'); - assert(ray_div(0, pow(2, 128) - 1) == 0, 'Wrong result: 0 / 2**128 -1'); - assert(ray_div(ray(), ray()) == ray(), 'Wrong result: 1e27 / 1e27'); + assert_eq!(ray_div(pow(2, 128) - 1, ray()), pow(2, 128) - 1, "Wrong result: 2**128 -1 / 1e27"); + assert_eq!(ray_div(0, pow(2, 128) - 1), 0, "Wrong result: 0 / 2**128 -1"); + assert_eq!(ray_div(ray(), ray()), ray(), "Wrong result: 1e27 / 1e27"); } #[test] #[available_gas(2000000)] fn test_ray_div_fractions() { - assert(ray_div(ray() * 2, ray() * 2) == ray(), 'Wrong result: 2e27 / 2e27'); - assert(ray_div(ray(), ray() * 2) == half_ray(), 'Wrong result: 1e27 / 2e27'); + assert_eq!(ray_div(ray() * 2, ray() * 2), ray(), "Wrong result: 2e27 / 2e27"); + assert_eq!(ray_div(ray(), ray() * 2), half_ray(), "Wrong result: 1e27 / 2e27"); } #[test] @@ -143,8 +143,8 @@ fn test_ray_mul_rounding() { let a = pow(10, 18); let b = 95 * pow(10, 26) + 5647; let expected = 95 * pow(10, 17); - assert(ray_mul(a, b) == expected, 'Wrong rounding down: a * b'); - assert(ray_mul(b, a) == expected, 'Wrong rounding down: b * a'); + assert_eq!(ray_mul(a, b), expected, "Wrong rounding down: a * b"); + assert_eq!(ray_mul(b, a), expected, "Wrong rounding down: b * a"); } @@ -154,6 +154,6 @@ fn test_ray_mul_rounding_up() { let a = pow(10, 27) - 1; let b = 2; let expected = 2; - assert(ray_mul(a, b) == expected, 'Wrong rounding up: a * b'); - assert(ray_mul(b, a) == expected, 'Wrong rounding up: b * a'); + assert_eq!(ray_mul(a, b), expected, "Wrong rounding up: a * b"); + assert_eq!(ray_mul(b, a), expected, "Wrong rounding up: b * a"); } diff --git a/src/math/src/tests/zellers_congruence_test.cairo b/src/math/src/tests/zellers_congruence_test.cairo index e5953812..60abbf8f 100644 --- a/src/math/src/tests/zellers_congruence_test.cairo +++ b/src/math/src/tests/zellers_congruence_test.cairo @@ -5,11 +5,11 @@ fn test_case(day: u128, month: u128, year: u128, expected: u128, error_expected: let day = day_of_week(day, month, year); // If error is expected, day must be none if error_expected { - assert(day.is_none(), 'expected error'); + assert!(day.is_none(), "expected error"); } // Otherwise, unwrap the day and check it else { let day = day.unwrap(); - assert(day == expected, 'day is invalid'); + assert!(day == expected, "day is invalid"); } } diff --git a/src/merkle_tree/src/merkle_tree.cairo b/src/merkle_tree/src/merkle_tree.cairo index ebfb03e0..473cf59d 100644 --- a/src/merkle_tree/src/merkle_tree.cairo +++ b/src/merkle_tree/src/merkle_tree.cairo @@ -193,7 +193,7 @@ fn compute_proof, +Drop>( } // Compute next level - let mut next_level: Array = get_next_level(nodes.span(), ref hasher); + let next_level: Array = get_next_level(nodes.span(), ref hasher); // Find neighbor node let mut index_parent = 0; diff --git a/src/merkle_tree/src/tests/merkle_tree_test.cairo b/src/merkle_tree/src/tests/merkle_tree_test.cairo index 6b873ee7..db1a71e7 100644 --- a/src/merkle_tree/src/tests/merkle_tree_test.cairo +++ b/src/merkle_tree/src/tests/merkle_tree_test.cairo @@ -25,17 +25,17 @@ mod regular_call_merkle_tree_pedersen { // [Assert] Compute merkle root. let computed_root = merkle_tree.compute_root(leaf, valid_proof); - assert(computed_root == root, 'compute valid root failed'); + assert_eq!(computed_root, root, "compute valid root failed"); // [Assert] Compute merkle proof. let mut input_leaves = leaves; let index = 0; let computed_proof = merkle_tree.compute_proof(input_leaves, index); - assert(computed_proof == valid_proof, 'compute valid proof failed'); + assert_eq!(computed_proof, valid_proof, "compute valid proof failed"); // [Assert] Verify a valid proof. let result = merkle_tree.verify(root, leaf, valid_proof); - assert(result, 'verify valid proof failed'); + assert!(result, "verify valid proof failed"); // [Assert] Verify an invalid proof. let invalid_proof = array![ @@ -43,12 +43,12 @@ mod regular_call_merkle_tree_pedersen { ] .span(); let result = merkle_tree.verify(root, leaf, invalid_proof); - assert(!result, 'verify invalid proof failed'); + assert!(!result, "verify invalid proof failed"); // [Assert] Verify a valid proof with an invalid leaf. let invalid_leaf = 0x1 + 1; let result = merkle_tree.verify(root, invalid_leaf, valid_proof); - assert(!result, 'wrong result'); + assert!(!result, "wrong result"); } } @@ -67,7 +67,7 @@ fn merkle_tree_pedersen_test() { let computed_root = MerkleTreeImpl::< _, PedersenHasherImpl >::compute_root(ref merkle_tree, leaf, valid_proof); - assert(computed_root == root, 'compute valid root failed'); + assert_eq!(computed_root, root, "compute valid root failed"); // [Assert] Compute merkle proof. let mut input_leaves = leaves; @@ -75,13 +75,13 @@ fn merkle_tree_pedersen_test() { let computed_proof = MerkleTreeImpl::< _, PedersenHasherImpl >::compute_proof(ref merkle_tree, input_leaves, index); - assert(computed_proof == valid_proof, 'compute valid proof failed'); + assert_eq!(computed_proof, valid_proof, "compute valid proof failed"); // [Assert] Verify a valid proof. let result = MerkleTreeImpl::< _, PedersenHasherImpl >::verify(ref merkle_tree, root, leaf, valid_proof); - assert(result, 'verify valid proof failed'); + assert!(result, "verify valid proof failed"); // [Assert] Verify an invalid proof. let invalid_proof = array![ @@ -91,14 +91,14 @@ fn merkle_tree_pedersen_test() { let result = MerkleTreeImpl::< _, PedersenHasherImpl >::verify(ref merkle_tree, root, leaf, invalid_proof); - assert(!result, 'verify invalid proof failed'); + assert!(!result, "verify invalid proof failed"); // [Assert] Verify a valid proof with an invalid leaf. let invalid_leaf = 0x1 + 1; let result = MerkleTreeImpl::< _, PedersenHasherImpl >::verify(ref merkle_tree, root, invalid_leaf, valid_proof); - assert(!result, 'wrong result'); + assert!(!result, "wrong result"); } #[test] @@ -116,7 +116,7 @@ fn merkle_tree_poseidon_test() { let computed_root = MerkleTreeImpl::< _, PoseidonHasherImpl >::compute_root(ref merkle_tree, leaf, valid_proof); - assert(computed_root == root, 'compute valid root failed'); + assert_eq!(computed_root, root, "compute valid root failed"); // [Assert] Compute merkle proof. let mut input_leaves = leaves; @@ -124,13 +124,13 @@ fn merkle_tree_poseidon_test() { let computed_proof = MerkleTreeImpl::< _, PoseidonHasherImpl >::compute_proof(ref merkle_tree, input_leaves, index); - assert(computed_proof == valid_proof, 'compute valid proof failed'); + assert_eq!(computed_proof, valid_proof, "compute valid proof failed"); // [Assert] Verify a valid proof. let result = MerkleTreeImpl::< _, PoseidonHasherImpl >::verify(ref merkle_tree, root, leaf, valid_proof); - assert(result, 'verify valid proof failed'); + assert!(result, "verify valid proof failed"); // [Assert] Verify an invalid proof. let invalid_proof = array![ @@ -140,12 +140,12 @@ fn merkle_tree_poseidon_test() { let result = MerkleTreeImpl::< _, PoseidonHasherImpl >::verify(ref merkle_tree, root, leaf, invalid_proof); - assert(!result, 'verify invalid proof failed'); + assert!(!result, "verify invalid proof failed"); // [Assert] Verify a valid proof with an invalid leaf. let invalid_leaf = 0x1 + 1; let result = MerkleTreeImpl::< _, PoseidonHasherImpl >::verify(ref merkle_tree, root, invalid_leaf, valid_proof); - assert(!result, 'wrong result'); + assert!(!result, "wrong result"); } diff --git a/src/merkle_tree/src/tests/storage_proof_test.cairo b/src/merkle_tree/src/tests/storage_proof_test.cairo index 6a24f32f..fea8629d 100644 --- a/src/merkle_tree/src/tests/storage_proof_test.cairo +++ b/src/merkle_tree/src/tests/storage_proof_test.cairo @@ -16,7 +16,7 @@ fn balance_lsb_proof_test() { let expected_value = 8700000000000000005; let proof = balance_proof(); let value = verify(state_commitment, contract_address, storage_address, proof); - assert(expected_value == value, 'wrong value'); + assert_eq!(expected_value, value, "wrong value"); } #[test] @@ -29,7 +29,7 @@ fn balance_msb_proof_test() { let expected_value = 8700000000000000005; let proof = balance_proof(); let value = verify(state_commitment, contract_address, storage_address, proof); - assert(expected_value == value, 'wrong value'); + assert_eq!(expected_value, value, "wrong value"); } #[test] @@ -42,7 +42,7 @@ fn wrong_contract_address_proof_test() { let expected_value = 8700000000000000005; let proof = balance_proof(); let value = verify(state_commitment, contract_address, storage_address, proof); - assert(expected_value == value, 'wrong value'); + assert_eq!(expected_value, value, "wrong value"); } #[test] @@ -54,5 +54,5 @@ fn total_balance_lsb_proof_test() { let expected_value = 2970506847688829412026631; let proof = total_balance_proof(); let value = verify(state_commitment, contract_address, storage_address, proof); - assert(expected_value == value, 'wrong value'); + assert_eq!(expected_value, value, "wrong value"); } diff --git a/src/numeric/src/cumprod.cairo b/src/numeric/src/cumprod.cairo index 656a503e..5e91dc39 100644 --- a/src/numeric/src/cumprod.cairo +++ b/src/numeric/src/cumprod.cairo @@ -10,9 +10,8 @@ fn cumprod, +Copy, +Drop,>(mut sequence: Span) -> Array { assert(sequence.len() >= 1, 'Array must have at least 1 elt'); // [Compute] Interpolation - let mut array = array![]; let mut prev_value = *sequence.pop_front().unwrap(); - array.append(prev_value); + let mut array = array![prev_value]; loop { match sequence.pop_front() { Option::Some(current_value) => { diff --git a/src/numeric/src/cumsum.cairo b/src/numeric/src/cumsum.cairo index 6732e0c8..e36c4f0c 100644 --- a/src/numeric/src/cumsum.cairo +++ b/src/numeric/src/cumsum.cairo @@ -10,9 +10,8 @@ fn cumsum, +Copy, +Drop,>(mut sequence: Span) -> Array { assert(sequence.len() >= 1, 'Array must have at least 1 elt'); // [Compute] Interpolation - let mut array = array![]; let mut prev_value = *sequence.pop_front().unwrap(); - array.append(prev_value); + let mut array = array![prev_value]; loop { match sequence.pop_front() { Option::Some(current_value) => { diff --git a/src/numeric/src/diff.cairo b/src/numeric/src/diff.cairo index 2aa68312..6052beed 100644 --- a/src/numeric/src/diff.cairo +++ b/src/numeric/src/diff.cairo @@ -12,9 +12,8 @@ fn diff, +Sub, +Copy, +Drop, +Zeroable,>( assert(sequence.len() >= 1, 'Array must have at least 1 elt'); // [Compute] Interpolation - let mut array = array![]; - array.append(Zeroable::zero()); let mut prev_value = *sequence.pop_front().unwrap(); + let mut array = array![Zeroable::zero()]; loop { match sequence.pop_front() { Option::Some(current_value) => { diff --git a/src/numeric/src/integers.cairo b/src/numeric/src/integers.cairo index 03111de5..fbd4f8b7 100644 --- a/src/numeric/src/integers.cairo +++ b/src/numeric/src/integers.cairo @@ -24,11 +24,8 @@ impl U32BytesImpl of UIntBytes { let offset: u32 = len - 1; let mut result: u32 = 0; let mut i: u32 = 0; - loop { - if i == len { - break; - } - let byte: u32 = (*input.at(i)).into(); + while i != len { + let byte: u32 = (*input[i]).into(); result += BitShift::shl(byte, 8 * (offset - i)); i += 1; @@ -45,10 +42,7 @@ impl U32BytesImpl of UIntBytes { let bytes_used: u32 = self.bytes_used().into(); let mut bytes: Array = Default::default(); let mut i = 0; - loop { - if i == bytes_used { - break; - } + while i != bytes_used { let val = BitShift::shr(self, 8 * (bytes_used.try_into().unwrap() - i - 1)); bytes.append((val & 0xFF).try_into().unwrap()); i += 1; diff --git a/src/numeric/src/interpolate.cairo b/src/numeric/src/interpolate.cairo index e0ebae95..fa8bdc51 100644 --- a/src/numeric/src/interpolate.cairo +++ b/src/numeric/src/interpolate.cairo @@ -43,18 +43,16 @@ fn interpolate< // [Check] Extrapolation if x <= *xs[0] { - let y = match extrapolation { + return match extrapolation { Extrapolation::Null(()) => Zeroable::zero(), Extrapolation::Constant(()) => *ys[0], }; - return y; } if x >= *xs[xs.len() - 1] { - let y = match extrapolation { + return match extrapolation { Extrapolation::Null(()) => Zeroable::zero(), Extrapolation::Constant(()) => *ys[xs.len() - 1], }; - return y; } // [Compute] Interpolation, could be optimized with binary search diff --git a/src/numeric/src/tests/cumprod_test.cairo b/src/numeric/src/tests/cumprod_test.cairo index 903bbb6e..387c6ce3 100644 --- a/src/numeric/src/tests/cumprod_test.cairo +++ b/src/numeric/src/tests/cumprod_test.cairo @@ -5,9 +5,9 @@ use alexandria_numeric::cumprod::cumprod; fn cumprod_test() { let xs: Array = array![3, 5, 7]; let ys = cumprod(xs.span()); - assert(*ys[0] == *xs[0], 'wrong value at index 0'); - assert(*ys[1] == *xs[0] * *xs[1], 'wrong value at index 1'); - assert(*ys[2] == *xs[0] * *xs[1] * *xs[2], 'wrong value at index 2'); + assert_eq!(*ys[0], *xs[0], "wrong value at index 0"); + assert_eq!(*ys[1], *xs[0] * *xs[1], "wrong value at index 1"); + assert_eq!(*ys[2], *xs[0] * *xs[1] * *xs[2], "wrong value at index 2"); } #[test] diff --git a/src/numeric/src/tests/cumsum_test.cairo b/src/numeric/src/tests/cumsum_test.cairo index dacb65f0..93f6717b 100644 --- a/src/numeric/src/tests/cumsum_test.cairo +++ b/src/numeric/src/tests/cumsum_test.cairo @@ -5,9 +5,9 @@ use alexandria_numeric::cumsum::cumsum; fn cumsum_test() { let xs: Array = array![3, 5, 7]; let ys = cumsum(xs.span()); - assert(*ys[0] == *xs[0], 'wrong value at index 0'); - assert(*ys[1] == *xs[0] + *xs[1], 'wrong value at index 1'); - assert(*ys[2] == *xs[0] + *xs[1] + *xs[2], 'wrong value at index 2'); + assert_eq!(*ys[0], *xs[0], "wrong value at index 0"); + assert_eq!(*ys[1], *xs[0] + *xs[1], "wrong value at index 1"); + assert_eq!(*ys[2], *xs[0] + *xs[1] + *xs[2], "wrong value at index 2"); } #[test] diff --git a/src/numeric/src/tests/diff_test.cairo b/src/numeric/src/tests/diff_test.cairo index 1a571668..5b0063e0 100644 --- a/src/numeric/src/tests/diff_test.cairo +++ b/src/numeric/src/tests/diff_test.cairo @@ -5,9 +5,9 @@ use alexandria_numeric::diff::diff; fn diff_test() { let xs = array![3, 5, 7]; let ys = diff(xs.span()); - assert(*ys[0] == 0_u256, 'wrong value at index 0'); - assert(*ys[1] == *xs[1] - *xs[0], 'wrong value at index 1'); - assert(*ys[2] == *xs[2] - *xs[1], 'wrong value at index 2'); + assert_eq!(*ys[0], 0_u256, "wrong value at index 0"); + assert_eq!(*ys[1], *xs[1] - *xs[0], "wrong value at index 1"); + assert_eq!(*ys[2], *xs[2] - *xs[1], "wrong value at index 2"); } #[test] diff --git a/src/numeric/src/tests/integers_test.cairo b/src/numeric/src/tests/integers_test.cairo index ea03e952..6bcba438 100644 --- a/src/numeric/src/tests/integers_test.cairo +++ b/src/numeric/src/tests/integers_test.cairo @@ -6,8 +6,8 @@ fn test_u32_from_bytes() { let input: Array = array![0xf4, 0x32, 0x15, 0x62]; let res: Option = UIntBytes::from_bytes(input.span()); - assert(res.is_some(), 'should have a value'); - assert(res.unwrap() == 0xf4321562, 'wrong result value'); + assert!(res.is_some(), "should have a value"); + assert_eq!(res.unwrap(), 0xf4321562, "wrong result value"); } #[test] @@ -16,7 +16,7 @@ fn test_u32_from_bytes_too_big() { let input: Array = array![0xf4, 0x32, 0x15, 0x62, 0x01]; let res: Option = UIntBytes::from_bytes(input.span()); - assert(res.is_none(), 'should not have a value'); + assert!(res.is_none(), "should not have a value"); } @@ -26,11 +26,11 @@ fn test_u32_to_bytes_full() { let input: u32 = 0xf4321562; let res: Span = input.to_bytes(); - assert(res.len() == 4, 'wrong result length'); - assert(*res[0] == 0xf4, 'wrong result value'); - assert(*res[1] == 0x32, 'wrong result value'); - assert(*res[2] == 0x15, 'wrong result value'); - assert(*res[3] == 0x62, 'wrong result value'); + assert_eq!(res.len(), 4, "wrong result length"); + assert_eq!(*res[0], 0xf4, "wrong result value"); + assert_eq!(*res[1], 0x32, "wrong result value"); + assert_eq!(*res[2], 0x15, "wrong result value"); + assert_eq!(*res[3], 0x62, "wrong result value"); } #[test] @@ -39,10 +39,10 @@ fn test_u32_to_bytes_partial() { let input: u32 = 0xf43215; let res: Span = input.to_bytes(); - assert(res.len() == 3, 'wrong result length'); - assert(*res[0] == 0xf4, 'wrong result value'); - assert(*res[1] == 0x32, 'wrong result value'); - assert(*res[2] == 0x15, 'wrong result value'); + assert_eq!(res.len(), 3, "wrong result length"); + assert_eq!(*res[0], 0xf4, "wrong result value"); + assert_eq!(*res[1], 0x32, "wrong result value"); + assert_eq!(*res[2], 0x15, "wrong result value"); } @@ -52,9 +52,9 @@ fn test_u32_to_bytes_leading_zeros() { let input: u32 = 0x00f432; let res: Span = input.to_bytes(); - assert(res.len() == 2, 'wrong result length'); - assert(*res[0] == 0xf4, 'wrong result value'); - assert(*res[1] == 0x32, 'wrong result value'); + assert_eq!(res.len(), 2, "wrong result length"); + assert_eq!(*res[0], 0xf4, "wrong result value"); + assert_eq!(*res[1], 0x32, "wrong result value"); } #[test] @@ -63,7 +63,7 @@ fn test_u32_bytes_used() { let len: u32 = 0x1234; let bytes_count = len.bytes_used(); - assert(bytes_count == 2, 'wrong bytes count'); + assert_eq!(bytes_count, 2, "wrong bytes count"); } #[test] @@ -72,5 +72,5 @@ fn test_u32_bytes_used_leading_zeroes() { let len: u32 = 0x001234; let bytes_count = len.bytes_used(); - assert(bytes_count == 2, 'wrong bytes count'); + assert_eq!(bytes_count, 2, "wrong bytes count"); } diff --git a/src/numeric/src/tests/trapezoidal_rule_test.cairo b/src/numeric/src/tests/trapezoidal_rule_test.cairo index 8d30d530..2722a727 100644 --- a/src/numeric/src/tests/trapezoidal_rule_test.cairo +++ b/src/numeric/src/tests/trapezoidal_rule_test.cairo @@ -5,7 +5,7 @@ use alexandria_numeric::trapezoidal_rule::trapezoidal_rule; fn trapezoidal_rule_test() { let xs: Array:: = array![3, 5, 7]; let ys = array![11, 13, 17]; - assert(trapezoidal_rule(xs.span(), ys.span()) == 54, 'invalid integral'); + assert_eq!(trapezoidal_rule(xs.span(), ys.span()), 54, "invalid integral"); } #[test] diff --git a/src/numeric/src/trapezoidal_rule.cairo b/src/numeric/src/trapezoidal_rule.cairo index 7d370a25..d6c72161 100644 --- a/src/numeric/src/trapezoidal_rule.cairo +++ b/src/numeric/src/trapezoidal_rule.cairo @@ -29,10 +29,7 @@ fn trapezoidal_rule< // [Compute] Trapezoidal rule let mut index = 0; let mut value = Zeroable::zero(); - loop { - if index + 1 == xs.len() { - break; - } + while index + 1 != xs.len() { assert(*xs[index + 1] > *xs[index], 'Abscissa must be sorted'); value += (*xs[index + 1] - *xs[index]) * (*ys[index] + *ys[index + 1]); index += 1; diff --git a/src/searching/src/binary_search.cairo b/src/searching/src/binary_search.cairo index 3780e824..f45430e1 100644 --- a/src/searching/src/binary_search.cairo +++ b/src/searching/src/binary_search.cairo @@ -1,25 +1,23 @@ -use array::SpanTrait; - fn binary_search, +Drop, +PartialEq, +PartialOrd>( span: Span, val: T ) -> Option { // Initial check - if (span.len() == 0) { + if span.len() == 0 { return Option::None; } let middle = span.len() / 2; - if (*span[middle] == val) { + if *span[middle] == val { return Option::Some(middle); } - if (span.len() == 1) { + if span.len() == 1 { return Option::None; } - if (*span[middle] > val) { - return (binary_search(span.slice(0, middle), val)); + if *span[middle] > val { + return binary_search(span.slice(0, middle), val); } let mut len = middle; - if (span.len() % 2 == 1) { + if span.len() % 2 == 1 { len += 1; } let val = binary_search(span.slice(middle, len), val); diff --git a/src/searching/src/bm_search.cairo b/src/searching/src/bm_search.cairo index 589aac72..584d7c26 100644 --- a/src/searching/src/bm_search.cairo +++ b/src/searching/src/bm_search.cairo @@ -16,21 +16,15 @@ fn bm_search(text: @ByteArray, pattern: @ByteArray) -> Array { return positions; } - let mut char_dict = felt252_dict_new::< - usize - >(); // Dictionary to store the last occurrence of each character in the pattern + // Dictionary to store the last occurrence of each character in the pattern + let mut char_dict = felt252_dict_new::(); let mut pattern_index = 0; // Index of the current character in the pattern // Build the character dictionary - loop { - if pattern_index == pattern_len { - break; - } + while pattern_index != pattern_len { let current_char = pattern.at(pattern_index).unwrap(); - char_dict - .insert( - current_char.into(), pattern_index + 1 - ); // Avoid 0 since felt252_dict initializes every entry to 0 by default + // Avoid 0 since felt252_dict initializes every entry to 0 by default + char_dict.insert(current_char.into(), pattern_index + 1); pattern_index += 1; }; @@ -45,13 +39,10 @@ fn bm_search(text: @ByteArray, pattern: @ByteArray) -> Array { let mut pattern_index = pattern_len; // Compare characters from right to left - loop { - if pattern_index == 0 - || @pattern - .at(pattern_index - 1) - .unwrap() != @text - .at(shift + pattern_index - 1) - .unwrap() { + while pattern_index != 0 { + let pattern_value = pattern.at(pattern_index - 1).unwrap(); + let text_value = text.at(shift + pattern_index - 1).unwrap(); + if pattern_value != text_value { break; } pattern_index -= 1; diff --git a/src/searching/src/dijkstra.cairo b/src/searching/src/dijkstra.cairo index 9cd56bd5..c5b7db9a 100644 --- a/src/searching/src/dijkstra.cairo +++ b/src/searching/src/dijkstra.cairo @@ -8,7 +8,6 @@ struct Node { weight: u128 } - /// Graph representation. struct Graph { nodes: Array, @@ -39,7 +38,7 @@ impl GraphImpl of GraphTrait { fn add_edge(ref self: Graph>>, source: u32, dest: u32, weight: u128) { let adj_nodes = self.adj_nodes.get(source.into()); let mut nodes: Array = array![]; - let mut is_null: bool = false; + let mut is_null = false; let node = Node { source, dest, weight }; let mut span = match match_nullable(adj_nodes) { FromNullableResult::Null => { @@ -51,16 +50,9 @@ impl GraphImpl of GraphTrait { }; // iterate over existing array to add new node - if (!is_null) { - let mut index = 0; - loop { - if index >= span.len() { - break; - } - - let new_node = *span.get(index).unwrap().unbox(); - nodes.append(new_node); - index += 1; + if !is_null { + while !span.is_empty() { + nodes.append(*span.pop_front().unwrap()); }; nodes.append(node); } @@ -82,16 +74,12 @@ fn dijkstra(ref self: Graph>>, source: u32) -> Felt252Dict>>, source: u32) -> Felt252Dict>>, source: u32) -> Felt252Dict>>, source: u32) -> Felt252Dict>>, source: u32) -> Felt252Dict, current_node: u32) -> bool { let mut index = 0; - let mut is_visited = false; let n = nodes.span(); loop { if index == n.len() { - break; + break false; } let source: u32 = *n.at(index); if source == current_node { - is_visited = true; - break; + break true; } index += 1; - }; - is_visited + } } diff --git a/src/searching/src/levenshtein_distance.cairo b/src/searching/src/levenshtein_distance.cairo index 59c7eb68..83b8c0e2 100644 --- a/src/searching/src/levenshtein_distance.cairo +++ b/src/searching/src/levenshtein_distance.cairo @@ -1,7 +1,6 @@ // The Levenshtein Distance use dict::Felt252DictTrait; - /// Compute the edit distance between two byte arrays /// * `arr1` - The first byte array. /// * `arr2` - The second byte array. @@ -20,33 +19,24 @@ fn levenshtein_distance(arr1: @ByteArray, arr2: @ByteArray) -> usize { // Initialize a dictionary to store previous distances, with keys and values as indices let mut prev_distances = felt252_dict_new::(); let mut index: usize = 0; - loop { - // Break the loop when index equals the length of the first array plus 1 - if index == arr1_len + 1 { - break; - } + // Break the loop when index equals the length of the first array plus 1 + while index != arr1_len + 1 { prev_distances.insert(index.into(), index); index += 1; }; // Initialize a variable to keep track of the current row let mut current_row: usize = 0; - loop { - // Break the loop when current row equals the length of the second array - if current_row == arr2_len { - break; - } + // Break the loop when current row equals the length of the second array + while current_row != arr2_len { let second_array_element = arr2.at(current_row).unwrap(); let mut previous_substitution_cost = prev_distances.get(0); prev_distances.insert(0, current_row + 1); // Initialize a variable to keep track of the current column let mut current_column: usize = 0; - loop { - // Break the loop when current column equals the length of the first array - if current_column == arr1_len { - break; - } + // Break the loop when current column equals the length of the first array + while current_column != arr1_len { let first_array_element = arr1.at(current_column).unwrap(); let deletion_cost = prev_distances.get(current_column.into()) + 1; let insertion_cost = prev_distances.get((current_column + 1).into()) + 1; @@ -57,13 +47,13 @@ fn levenshtein_distance(arr1: @ByteArray, arr2: @ByteArray) -> usize { }; previous_substitution_cost = prev_distances.get((current_column + 1).into()); - let mut min_cost = deletion_cost; - if insertion_cost < min_cost { - min_cost = insertion_cost; - } - if substitution_cost < min_cost { - min_cost = substitution_cost; - } + let min_cost = if insertion_cost < deletion_cost { + insertion_cost + } else if substitution_cost < deletion_cost { + substitution_cost + } else { + deletion_cost + }; prev_distances.insert((current_column + 1).into(), min_cost); current_column += 1 diff --git a/src/searching/src/tests/binary_search_test.cairo b/src/searching/src/tests/binary_search_test.cairo index 92a392cf..37329ee8 100644 --- a/src/searching/src/tests/binary_search_test.cairo +++ b/src/searching/src/tests/binary_search_test.cairo @@ -8,23 +8,23 @@ fn value_found() { let mut span = arr.span(); // Test with an even length - assert(binary_search(span, 100).unwrap() == 0, 'Should be index 0'); - assert(binary_search(span, 200).unwrap() == 1, 'Should be index 1'); - assert(binary_search(span, 300).unwrap() == 2, 'Should be index 2'); - assert(binary_search(span, 400).unwrap() == 3, 'Should be index 3'); - assert(binary_search(span, 500).unwrap() == 4, 'Should be index 4'); - assert(binary_search(span, 600).unwrap() == 5, 'Should be index 5'); + assert_eq!(binary_search(span, 100).unwrap(), 0, "Should be index 0"); + assert_eq!(binary_search(span, 200).unwrap(), 1, "Should be index 1"); + assert_eq!(binary_search(span, 300).unwrap(), 2, "Should be index 2"); + assert_eq!(binary_search(span, 400).unwrap(), 3, "Should be index 3"); + assert_eq!(binary_search(span, 500).unwrap(), 4, "Should be index 4"); + assert_eq!(binary_search(span, 600).unwrap(), 5, "Should be index 5"); // Odd length arr.append(700); span = arr.span(); - assert(binary_search(span, 100).unwrap() == 0, 'Should be index 0'); - assert(binary_search(span, 200).unwrap() == 1, 'Should be index 1'); - assert(binary_search(span, 300).unwrap() == 2, 'Should be index 2'); - assert(binary_search(span, 400).unwrap() == 3, 'Should be index 3'); - assert(binary_search(span, 500).unwrap() == 4, 'Should be index 4'); - assert(binary_search(span, 600).unwrap() == 5, 'Should be index 5'); - assert(binary_search(span, 700).unwrap() == 6, 'Should be index 6'); + assert_eq!(binary_search(span, 100).unwrap(), 0, "Should be index 0"); + assert_eq!(binary_search(span, 200).unwrap(), 1, "Should be index 1"); + assert_eq!(binary_search(span, 300).unwrap(), 2, "Should be index 2"); + assert_eq!(binary_search(span, 400).unwrap(), 3, "Should be index 3"); + assert_eq!(binary_search(span, 500).unwrap(), 4, "Should be index 4"); + assert_eq!(binary_search(span, 600).unwrap(), 5, "Should be index 5"); + assert_eq!(binary_search(span, 700).unwrap(), 6, "Should be index 6"); } #[test] @@ -34,16 +34,16 @@ fn value_not_found() { // Test with an even length let mut span = arr.span(); - assert(binary_search(span, 20).is_none(), 'value was found'); - assert(binary_search(span, 42000).is_none(), 'value was found'); - assert(binary_search(span, 760).is_none(), 'value was found'); + assert!(binary_search(span, 20).is_none(), "value was found"); + assert!(binary_search(span, 42000).is_none(), "value was found"); + assert!(binary_search(span, 760).is_none(), "value was found"); // Odd length arr.append(700); // 6 span = arr.span(); - assert(binary_search(span, 20).is_none(), 'value was found'); - assert(binary_search(span, 42000).is_none(), 'value was found'); - assert(binary_search(span, 760).is_none(), 'value was found'); + assert!(binary_search(span, 20).is_none(), "value was found"); + assert!(binary_search(span, 42000).is_none(), "value was found"); + assert!(binary_search(span, 760).is_none(), "value was found"); } #[test] diff --git a/src/searching/src/tests/bm_search_test.cairo b/src/searching/src/tests/bm_search_test.cairo index c477e213..959a0824 100644 --- a/src/searching/src/tests/bm_search_test.cairo +++ b/src/searching/src/tests/bm_search_test.cairo @@ -64,7 +64,7 @@ fn bm_search_test_1() { let positions = bm_search(@text, @pattern); let ground_truth: Array = array![1, 11, 20]; - assert(is_equal(positions.span(), ground_truth.span()), 'invalid result'); + assert!(is_equal(positions.span(), ground_truth.span()), "invalid result"); } #[test] @@ -105,7 +105,7 @@ fn bm_search_test_2() { let positions = bm_search(@text, @pattern); let ground_truth: Array = array![]; - assert(is_equal(positions.span(), ground_truth.span()), 'invalid result'); + assert!(is_equal(positions.span(), ground_truth.span()), "invalid result"); } #[test] @@ -146,5 +146,5 @@ fn bm_search_test_3() { let positions = bm_search(@text, @pattern); let ground_truth: Array = array![3, 13, 22]; - assert(is_equal(positions.span(), ground_truth.span()), 'invalid result'); + assert!(is_equal(positions.span(), ground_truth.span()), "invalid result"); } diff --git a/src/searching/src/tests/dijkstra_test.cairo b/src/searching/src/tests/dijkstra_test.cairo index e16d89d6..bd39e379 100644 --- a/src/searching/src/tests/dijkstra_test.cairo +++ b/src/searching/src/tests/dijkstra_test.cairo @@ -16,7 +16,7 @@ fn add_edge() { GraphTrait::add_edge(ref graph, 2, 1, 2); GraphTrait::add_edge(ref graph, 2, 3, 3); - assert(graph.nodes.len() == 6, 'wrong node number'); + assert!(graph.nodes.len() == 6, "wrong node number"); let val = graph.adj_nodes.get(source.into()); let span = match match_nullable(val) { @@ -24,15 +24,15 @@ fn add_edge() { FromNullableResult::NotNull(val) => { val.unbox() }, }; - assert(span.len() == 4, 'wrong nb of adj edge for node 0'); + assert!(span.len() == 4, "wrong nb of adj edge for node 0"); let new_node = *span.get(1).unwrap().unbox(); - assert(new_node.dest == dest + 1, 'Wrong dest in adj edge'); - assert(new_node.weight == weight + 1, 'Wrong weight in adj edge'); + assert!(new_node.dest == dest + 1, "Wrong dest in adj edge"); + assert!(new_node.weight == weight + 1, "Wrong weight in adj edge"); let new_node = *span.get(3).unwrap().unbox(); - assert(new_node.dest == dest + 3, 'Wrong dest in adj edge'); - assert(new_node.weight == weight + 3, 'Wrong weight in adj edge'); + assert!(new_node.dest == dest + 3, "Wrong dest in adj edge"); + assert!(new_node.weight == weight + 3, "Wrong weight in adj edge"); let val = graph.adj_nodes.get(2.into()); @@ -41,7 +41,7 @@ fn add_edge() { FromNullableResult::NotNull(val) => { val.unbox() }, }; - assert(span.len() == 2, 'wrong nb of adj edge for node 2'); + assert!(span.len() == 2, "wrong nb of adj edge for node 2"); } @@ -59,12 +59,12 @@ fn calculate_shortest_path() { let mut results: Felt252Dict = GraphTrait::shortest_path(ref graph, 0_u32); - assert(results.get(0.into()) == 0, 'Wrong weight for node 0'); - assert(results.get(1.into()) == 5, 'Wrong weight for node 1'); - assert(results.get(2.into()) == 3, 'Wrong weight for node 2'); - assert(results.get(3.into()) == 2, 'Wrong weight for node 3'); - assert(results.get(4.into()) == 3, 'Wrong weight for node 4'); - assert(results.get(5.into()) == 3, 'Wrong weight for node 5'); + assert!(results.get(0.into()) == 0, "Wrong weight for node 0"); + assert!(results.get(1.into()) == 5, "Wrong weight for node 1"); + assert!(results.get(2.into()) == 3, "Wrong weight for node 2"); + assert!(results.get(3.into()) == 2, "Wrong weight for node 3"); + assert!(results.get(4.into()) == 3, "Wrong weight for node 4"); + assert!(results.get(5.into()) == 3, "Wrong weight for node 5"); } #[test] @@ -80,11 +80,11 @@ fn calculate_shortest_path_random() { let mut results: Felt252Dict = GraphTrait::shortest_path(ref graph, 0_u32); - assert(results.get(0.into()) == 0, 'Wrong weight for node 0'); - assert(results.get(2.into()) == 4, 'Wrong weight for node 2'); - assert(results.get(3.into()) == 5, 'Wrong weight for node 3'); - assert(results.get(1.into()) == 8, 'Wrong weight for node 1'); - assert(results.get(4.into()) == 7, 'Wrong weight for node 4'); + assert!(results.get(0.into()) == 0, "Wrong weight for node 0"); + assert!(results.get(2.into()) == 4, "Wrong weight for node 2"); + assert!(results.get(3.into()) == 5, "Wrong weight for node 3"); + assert!(results.get(1.into()) == 8, "Wrong weight for node 1"); + assert!(results.get(4.into()) == 7, "Wrong weight for node 4"); } @@ -101,11 +101,11 @@ fn calculate_shortest_path_node_visited() { let mut results: Felt252Dict = GraphTrait::shortest_path(ref graph, 0_u32); - assert(results.get(0.into()) == 0, 'Wrong weight for node 0'); - assert(results.get(1.into()) == 5, 'Wrong weight for node 1'); - assert(results.get(2.into()) == 3, 'Wrong weight for node 2'); - assert(results.get(3.into()) == 2, 'Wrong weight for node 3'); - assert(results.get(4.into()) == 3, 'Wrong weight for node 4'); - assert(results.get(5.into()) == 3, 'Wrong weight for node 5'); + assert!(results.get(0.into()) == 0, "Wrong weight for node 0"); + assert!(results.get(1.into()) == 5, "Wrong weight for node 1"); + assert!(results.get(2.into()) == 3, "Wrong weight for node 2"); + assert!(results.get(3.into()) == 2, "Wrong weight for node 3"); + assert!(results.get(4.into()) == 3, "Wrong weight for node 4"); + assert!(results.get(5.into()) == 3, "Wrong weight for node 5"); } diff --git a/src/searching/src/tests/levenshtein_distance_test.cairo b/src/searching/src/tests/levenshtein_distance_test.cairo index 5bd3e7c1..9a40b8bc 100644 --- a/src/searching/src/tests/levenshtein_distance_test.cairo +++ b/src/searching/src/tests/levenshtein_distance_test.cairo @@ -17,7 +17,7 @@ fn bm_search_test_1() { arr2.append_byte(0x47_u8); let dist = levenshtein_distance(@arr1, @arr2); - assert(dist == 2, 'invalid result'); + assert_eq!(dist, 2, "invalid result"); } #[test] @@ -27,7 +27,7 @@ fn bm_search_test_2() { let mut arr2: ByteArray = Default::default(); let dist = levenshtein_distance(@arr1, @arr2); - assert(dist == 0, 'invalid result'); + assert_eq!(dist, 0, "invalid result"); } #[test] @@ -38,7 +38,7 @@ fn bm_search_test_3() { arr2.append_byte(0x61_u8); let dist = levenshtein_distance(@arr1, @arr2); - assert(dist == 1, 'invalid result'); + assert_eq!(dist, 1, "invalid result"); } #[test] @@ -49,7 +49,7 @@ fn bm_search_test_4() { let mut arr2: ByteArray = Default::default(); let dist = levenshtein_distance(@arr1, @arr2); - assert(dist == 1, 'invalid result'); + assert_eq!(dist, 1, "invalid result"); } #[test] @@ -62,7 +62,7 @@ fn bm_search_test_5() { arr2.append_byte(0x61_u8); let dist = levenshtein_distance(@arr1, @arr2); - assert(dist == 1, 'invalid result'); + assert_eq!(dist, 1, "invalid result"); } #[test] @@ -86,7 +86,7 @@ fn bm_search_test_6() { arr2.append_byte(0x72_u8); let dist = levenshtein_distance(@arr1, @arr2); - assert(dist == 0, 'invalid result'); + assert_eq!(dist, 0, "invalid result"); } #[test] @@ -110,5 +110,5 @@ fn bm_search_test_7() { arr2.append_byte(0x6f_u8); let dist = levenshtein_distance(@arr1, @arr2); - assert(dist == 6, 'invalid result'); + assert_eq!(dist, 6, "invalid result"); } diff --git a/src/sorting/src/merge_sort.cairo b/src/sorting/src/merge_sort.cairo index 973b38f9..9149a385 100644 --- a/src/sorting/src/merge_sort.cairo +++ b/src/sorting/src/merge_sort.cairo @@ -16,8 +16,8 @@ fn merge, +Drop, +PartialOrd>(mut arr: Array) -> Array { let (mut left_arr, mut right_arr) = split_array(ref arr, middle); // Recursively sort the left and right arrays - let mut sorted_left = merge(left_arr); - let mut sorted_right = merge(right_arr); + let sorted_left = merge(left_arr); + let sorted_right = merge(right_arr); let mut result_arr = array![]; merge_recursive(sorted_left, sorted_right, ref result_arr, 0, 0); diff --git a/src/sorting/src/quick_sort.cairo b/src/sorting/src/quick_sort.cairo index 7d729adb..3ac96414 100644 --- a/src/sorting/src/quick_sort.cairo +++ b/src/sorting/src/quick_sort.cairo @@ -29,22 +29,12 @@ fn quick_sort_range, +Drop, +PartialOrd, +PartialEq, +Felt2 let mut l = left; let mut r = right; - loop { - if l >= r { - break; - } - - loop { - if (l >= r) || (array[r] < array[left]) { - break; - } + while l < r { + while (l < r) && (array[r] >= array[left]) { r -= 1; }; - loop { - if (l >= r) || (array[l] > array[left]) { - break; - } + while (l < r) && (array[l] <= array[left]) { l += 1; }; diff --git a/src/sorting/src/tests/bubble_sort_test.cairo b/src/sorting/src/tests/bubble_sort_test.cairo index a52c3003..38dec131 100644 --- a/src/sorting/src/tests/bubble_sort_test.cairo +++ b/src/sorting/src/tests/bubble_sort_test.cairo @@ -3,155 +3,155 @@ use alexandria_sorting::{is_equal, bubble_sort}; #[test] #[available_gas(20000000000000)] fn bubblesort_test() { - let mut data = array![4_u32, 2_u32, 1_u32, 3_u32, 5_u32, 0_u32]; - let mut correct = array![0_u32, 1_u32, 2_u32, 3_u32, 4_u32, 5_u32]; + let data = array![4_u32, 2, 1, 3, 5, 0]; + let correct = array![0_u32, 1, 2, 3, 4, 5]; let sorted = bubble_sort::bubble_sort_elements(data, true); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_empty() { - let mut data = array![]; - let mut correct = array![]; + let data = array![]; + let correct = array![]; let sorted = bubble_sort::bubble_sort_elements(data, true); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_one_element() { - let mut data = array![2_u32]; - let mut correct = array![2_u32]; + let data = array![2_u32]; + let correct = array![2_u32]; let sorted = bubble_sort::bubble_sort_elements(data, true); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_pre_sorted() { - let mut data = array![1_u32, 2_u32, 3_u32, 4_u32]; - let mut correct = array![1_u32, 2_u32, 3_u32, 4_u32]; + let data = array![1_u32, 2, 3, 4]; + let correct = array![1_u32, 2, 3, 4]; let sorted = bubble_sort::bubble_sort_elements(data, true); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_pre_sorted_decreasing() { - let mut data = array![4_u32, 3_u32, 2_u32, 1_u32]; - let mut correct = array![1_u32, 2_u32, 3_u32, 4_u32]; + let data = array![4_u32, 3, 2, 1]; + let correct = array![1_u32, 2, 3, 4]; let sorted = bubble_sort::bubble_sort_elements(data, true); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_pre_sorted_2_same_values() { - let mut data = array![1_u32, 2_u32, 2_u32, 4_u32]; - let mut correct = array![1_u32, 2_u32, 2_u32, 4_u32]; + let data = array![1_u32, 2, 2, 4]; + let correct = array![1_u32, 2, 2, 4]; let sorted = bubble_sort::bubble_sort_elements(data, true); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_2_same_values() { - let mut data = array![1_u32, 2_u32, 4_u32, 2_u32]; - let mut correct = array![1_u32, 2_u32, 2_u32, 4_u32]; + let data = array![1_u32, 2, 4, 2]; + let correct = array![1_u32, 2, 2, 4]; let sorted = bubble_sort::bubble_sort_elements(data, true); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(20000000000000)] fn bubblesort_test_dsc() { - let mut data = array![4_u32, 2_u32, 1_u32, 3_u32, 5_u32, 0_u32]; - let mut correct = array![5_u32, 4_u32, 3_u32, 2_u32, 1_u32, 0_u32]; + let data = array![4_u32, 2, 1, 3, 5, 0]; + let correct = array![5_u32, 4, 3, 2, 1, 0]; let sorted = bubble_sort::bubble_sort_elements(data, false); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_empty_dsc() { - let mut data = array![]; - let mut correct = array![]; + let data = array![]; + let correct = array![]; let sorted = bubble_sort::bubble_sort_elements(data, false); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_one_element_dsc() { - let mut data = array![2_u32]; - let mut correct = array![2_u32]; + let data = array![2_u32]; + let correct = array![2_u32]; let sorted = bubble_sort::bubble_sort_elements(data, false); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_pre_sorted_dsc() { - let mut data = array![1_u32, 2_u32, 3_u32, 4_u32]; - let mut correct = array![4_u32, 3_u32, 2_u32, 1_u32]; + let data = array![1_u32, 2, 3, 4]; + let correct = array![4_u32, 3, 2, 1]; let sorted = bubble_sort::bubble_sort_elements(data, false); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_pre_sorted_decreasing_dsc() { - let mut data = array![4_u32, 3_u32, 2_u32, 1_u32]; - let mut correct = array![4_u32, 3_u32, 2_u32, 1_u32]; + let data = array![4_u32, 3, 2, 1]; + let correct = array![4_u32, 3, 2, 1]; let sorted = bubble_sort::bubble_sort_elements(data, false); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_pre_sorted_2_same_values_dsc() { - let mut data = array![1_u32, 2_u32, 2_u32, 4_u32]; - let mut correct = array![4_u32, 2_u32, 2_u32, 1_u32]; + let data = array![1_u32, 2, 2, 4]; + let correct = array![4_u32, 2, 2, 1]; let sorted = bubble_sort::bubble_sort_elements(data, false); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn bubblesort_test_2_same_values_dsc() { - let mut data = array![1_u32, 2_u32, 4_u32, 2_u32]; - let mut correct = array![4_u32, 2_u32, 2_u32, 1_u32]; + let data = array![1_u32, 2, 4, 2]; + let correct = array![4_u32, 2, 2, 1]; let sorted = bubble_sort::bubble_sort_elements(data, false); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } diff --git a/src/sorting/src/tests/merge_sort_test.cairo b/src/sorting/src/tests/merge_sort_test.cairo index d5a6fb8b..1a15f74f 100644 --- a/src/sorting/src/tests/merge_sort_test.cairo +++ b/src/sorting/src/tests/merge_sort_test.cairo @@ -3,77 +3,77 @@ use alexandria_sorting::{is_equal, merge_sort::merge}; #[test] #[available_gas(2000000000)] fn mergesort_test() { - let data = array![7_u32, 4_u32, 2_u32, 6_u32, 1_u32, 3_u32, 5_u32, 8_u32, 0_u32]; - let correct = array![0_u32, 1_u32, 2_u32, 3_u32, 4_u32, 5_u32, 6_u32, 7_u32, 8_u32].span(); + let data = array![7_u32, 4, 2, 6, 1, 3, 5, 8, 0]; + let correct = array![0_u32, 1, 2, 3, 4, 5, 6, 7, 8].span(); - let mut sorted = merge(data).span(); + let sorted = merge(data).span(); - assert(is_equal(sorted, correct), 'invalid result'); + assert!(is_equal(sorted, correct), "invalid result"); } #[test] #[available_gas(2000000)] fn mergesort_test_2_pre_sorted_decreasing() { - let mut data = array![4_u32, 3_u32, 2_u32, 1_u32]; - let mut correct = array![1_u32, 2_u32, 3_u32, 4_u32]; + let data = array![4_u32, 3, 2, 1]; + let correct = array![1_u32, 2, 3, 4]; let sorted = merge(data); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn mergesort_test_empty() { - let mut data = array![]; + let data = array![]; - let mut correct = array![]; + let correct = array![]; let sorted = merge(data); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn mergesort_test_one_element() { - let mut data = array![2_u32]; - let mut correct = array![2_u32]; + let data = array![2_u32]; + let correct = array![2_u32]; - let mut sorted = merge(data); + let sorted = merge(data); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn mergesort_test_pre_sorted() { - let mut data = array![1_u32, 2_u32, 3_u32, 4_u32]; - let mut correct = array![1_u32, 2_u32, 3_u32, 4_u32]; + let data = array![1_u32, 2, 3, 4]; + let correct = array![1_u32, 2, 3, 4]; let sorted = merge(data); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn mergesort_test_2_same_values() { - let mut data = array![1_u32, 2_u32, 3_u32, 2_u32, 4_u32]; - let mut correct = array![1_u32, 2_u32, 2_u32, 3_u32, 4_u32]; + let data = array![1_u32, 2, 3, 2, 4]; + let correct = array![1_u32, 2, 2, 3, 4]; let sorted = merge(data); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn mergesort_test_2_same_values_pre_sorted() { - let mut data = array![1_u32, 2_u32, 2_u32, 3_u32, 4_u32]; - let mut correct = array![1_u32, 2_u32, 2_u32, 3_u32, 4_u32]; + let data = array![1_u32, 2, 2, 3, 4]; + let correct = array![1_u32, 2, 2, 3, 4]; let sorted = merge(data); - assert(is_equal(sorted.span(), correct.span()), 'invalid result'); + assert!(is_equal(sorted.span(), correct.span()), "invalid result"); } diff --git a/src/sorting/src/tests/quick_sort_test.cairo b/src/sorting/src/tests/quick_sort_test.cairo index 1ce95d24..cc96033e 100644 --- a/src/sorting/src/tests/quick_sort_test.cairo +++ b/src/sorting/src/tests/quick_sort_test.cairo @@ -7,99 +7,99 @@ use core::option::OptionTrait; #[available_gas(20000000000000)] fn quicksort_test() { let mut data = VecTrait::::new(); - data.push(4_u32); - data.push(2_u32); - data.push(1_u32); - data.push(3_u32); - data.push(5_u32); - data.push(0_u32); - let mut correct = array![0_u32, 1_u32, 2_u32, 3_u32, 4_u32, 5_u32]; + data.push(4); + data.push(2); + data.push(1); + data.push(3); + data.push(5); + data.push(0); + let correct = array![0_u32, 1, 2, 3, 4, 5]; - let mut sorted = quick_sort::quick_sort(data); + let sorted = quick_sort::quick_sort(data); - assert(is_equal_vec(sorted, correct.span()), 'invalid result'); + assert!(is_equal_vec(sorted, correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn quicksort_test_empty() { - let mut data = VecTrait::::new(); - let mut correct = array![]; + let data = VecTrait::::new(); + let correct = array![]; - let mut sorted = quick_sort::quick_sort(data); + let sorted = quick_sort::quick_sort(data); - assert(is_equal_vec(sorted, correct.span()), 'invalid result'); + assert!(is_equal_vec(sorted, correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn quicksort_test_one_element() { let mut data = VecTrait::::new(); - data.push(2_u32); - let mut correct = array![2_u32]; + data.push(2); + let correct = array![2_u32]; - let mut sorted = quick_sort::quick_sort(data); + let sorted = quick_sort::quick_sort(data); - assert(is_equal_vec(sorted, correct.span()), 'invalid result'); + assert!(is_equal_vec(sorted, correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn quicksort_test_pre_sorted() { let mut data = VecTrait::::new(); - data.push(1_u32); - data.push(2_u32); - data.push(3_u32); - data.push(4_u32); - let mut correct = array![1_u32, 2_u32, 3_u32, 4_u32]; + data.push(1); + data.push(2); + data.push(3); + data.push(4); + let correct = array![1_u32, 2, 3, 4]; - let mut sorted = quick_sort::quick_sort(data); + let sorted = quick_sort::quick_sort(data); - assert(is_equal_vec(sorted, correct.span()), 'invalid result'); + assert!(is_equal_vec(sorted, correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn quicksort_test_pre_sorted_decreasing() { let mut data = VecTrait::::new(); - data.push(4_u32); - data.push(3_u32); - data.push(2_u32); - data.push(1_u32); - let mut correct = array![1_u32, 2_u32, 3_u32, 4_u32]; + data.push(4); + data.push(3); + data.push(2); + data.push(1); + let correct = array![1_u32, 2, 3, 4]; - let mut sorted = quick_sort::quick_sort(data); + let sorted = quick_sort::quick_sort(data); - assert(is_equal_vec(sorted, correct.span()), 'invalid result'); + assert!(is_equal_vec(sorted, correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn quicksort_test_pre_sorted_2_same_values() { let mut data = VecTrait::::new(); - data.push(1_u32); - data.push(2_u32); - data.push(2_u32); - data.push(4_u32); - let mut correct = array![1_u32, 2_u32, 2_u32, 4_u32]; + data.push(1); + data.push(2); + data.push(2); + data.push(4); + let correct = array![1_u32, 2, 2, 4]; - let mut sorted = quick_sort::quick_sort(data); + let sorted = quick_sort::quick_sort(data); - assert(is_equal_vec(sorted, correct.span()), 'invalid result'); + assert!(is_equal_vec(sorted, correct.span()), "invalid result"); } #[test] #[available_gas(2000000)] fn quicksort_test_2_same_values() { let mut data = VecTrait::::new(); - data.push(1_u32); - data.push(2_u32); - data.push(4_u32); - data.push(2_u32); - let mut correct = array![1_u32, 2_u32, 2_u32, 4_u32]; + data.push(1); + data.push(2); + data.push(4); + data.push(2); + let correct = array![1_u32, 2, 2, 4]; - let mut sorted = quick_sort::quick_sort(data); + let sorted = quick_sort::quick_sort(data); - assert(is_equal_vec(sorted, correct.span()), 'invalid result'); + assert!(is_equal_vec(sorted, correct.span()), "invalid result"); } diff --git a/src/storage/src/tests/list_test.cairo b/src/storage/src/tests/list_test.cairo index 21b58360..21e5ea00 100644 --- a/src/storage/src/tests/list_test.cairo +++ b/src/storage/src/tests/list_test.cairo @@ -147,7 +147,7 @@ mod tests { #[available_gas(100000000)] fn test_deploy() { let contract = deploy_mock(); - assert(contract.do_get_len() == (0, 0), 'do_get_len'); + assert_eq!(contract.do_get_len(), (0, 0), "do_get_len"); } #[test] @@ -155,25 +155,25 @@ mod tests { fn test_new_initializes_empty_list() { let contract = deploy_mock(); set_contract_address(contract.contract_address); - let mut contract_state = AListHolder::unsafe_new_contract_state(); + let contract_state = AListHolder::unsafe_new_contract_state(); let addresses_address = contract_state.addresses.address(); let addresses_list = ListTrait::::new(0, addresses_address); - assert(addresses_list.address_domain == 0, 'Address domain should be 0'); - assert(addresses_list.len() == 0, 'Initial length should be 0'); - assert(addresses_list.base.into() == addresses_address, 'Base address mismatch'); - assert(addresses_list.storage_size == 1, 'Storage size should be 1'); + assert_eq!(addresses_list.address_domain, 0, "Address domain should be 0"); + assert_eq!(addresses_list.len(), 0, "Initial length should be 0"); + assert_eq!(addresses_list.base.into(), addresses_address, "Base address mismatch"); + assert_eq!(addresses_list.storage_size, 1, "Storage size should be 1"); let numbers_address = contract_state.numbers.address(); let numbers_list = ListTrait::::new(0, numbers_address); - assert(numbers_list.address_domain == 0, 'Address domain should be 0'); - assert(numbers_list.len() == 0, 'Initial length should be 0'); - assert(numbers_list.base.into() == numbers_address, 'Base address mismatch'); - assert(numbers_list.storage_size == 2, 'Storage size should be 2'); + assert_eq!(numbers_list.address_domain, 0, "Address domain should be 0"); + assert_eq!(numbers_list.len(), 0, "Initial length should be 0"); + assert_eq!(numbers_list.base.into(), numbers_address, "Base address mismatch"); + assert_eq!(numbers_list.storage_size, 2, "Storage size should be 2"); // Check if both addresses and numbers lists are initialized to be empty - assert(contract.do_get_len() == (0, 0), 'Initial lengths should be 0'); - assert(contract.do_is_empty() == (true, true), 'Lists should be empty'); + assert_eq!(contract.do_get_len(), (0, 0), "Initial lengths should be 0"); + assert_eq!(contract.do_is_empty(), (true, true), "Lists should be empty"); } #[test] @@ -181,7 +181,7 @@ mod tests { fn test_new_then_fill_list() { let contract = deploy_mock(); set_contract_address(contract.contract_address); - let mut contract_state = AListHolder::unsafe_new_contract_state(); + let contract_state = AListHolder::unsafe_new_contract_state(); let addresses_address = contract_state.addresses.address(); let mut addresses_list = ListTrait::::new(0, addresses_address); @@ -193,11 +193,11 @@ mod tests { let _ = numbers_list.append(1); let _ = numbers_list.append(2); - assert(addresses_list.len() == 1, 'Addresses length should be 1'); - assert(numbers_list.len() == 2, 'Numbers length should be 2'); + assert_eq!(addresses_list.len(), 1, "Addresses length should be 1"); + assert_eq!(numbers_list.len(), 2, "Numbers length should be 2"); - assert(contract.do_get_len() == (1, 2), 'Lengths should be (1,2)'); - assert(contract.do_is_empty() == (false, false), 'Lists should not be empty'); + assert_eq!(contract.do_get_len(), (1, 2), "Lengths should be (1,2)"); + assert_eq!(contract.do_is_empty(), (false, false), "Lists should not be empty"); } #[test] @@ -209,10 +209,10 @@ mod tests { let empty_list = ListTrait::::fetch(0, storage_address).expect('List fetch failed'); - assert(empty_list.address_domain == 0, 'Address domain should be 0'); - assert(empty_list.len() == 0, 'Length should be 0'); - assert(empty_list.base.into() == storage_address, 'Base address mismatch'); - assert(empty_list.storage_size == 1, 'Storage size should be 1'); + assert_eq!(empty_list.address_domain, 0, "Address domain should be 0"); + assert_eq!(empty_list.len(), 0, "Length should be 0"); + assert_eq!(empty_list.base.into(), storage_address, "Base address mismatch"); + assert_eq!(empty_list.storage_size, 1, "Storage size should be 1"); } @@ -221,25 +221,25 @@ mod tests { fn test_fetch_existing_list() { let contract = deploy_mock(); set_contract_address(contract.contract_address); - let mut contract_state = AListHolder::unsafe_new_contract_state(); + let contract_state = AListHolder::unsafe_new_contract_state(); let mock_addr = mock_addr(); - assert(contract.do_append(mock_addr, 10) == (0, 0), '1st append idx'); - assert(contract.do_append(mock_addr, 20) == (1, 1), '2nd append idx'); + assert_eq!(contract.do_append(mock_addr, 10), (0, 0), "1st append idx"); + assert_eq!(contract.do_append(mock_addr, 20), (1, 1), "2nd append idx"); let addresses_address = contract_state.addresses.address(); let addresses_list = ListTrait::::fetch(0, addresses_address) .expect('List fetch failed'); - assert(addresses_list.address_domain == 0, 'Address domain should be 0'); - assert(addresses_list.len() == 2, 'Length should be 2'); - assert(addresses_list.base.into() == addresses_address, 'Base address mismatch'); - assert(addresses_list.storage_size == 1, 'Storage size should be 1'); + assert_eq!(addresses_list.address_domain, 0, "Address domain should be 0"); + assert_eq!(addresses_list.len(), 2, "Length should be 2"); + assert_eq!(addresses_list.base.into(), addresses_address, "Base address mismatch"); + assert_eq!(addresses_list.storage_size, 1, "Storage size should be 1"); let numbers_address = contract_state.numbers.address(); let numbers_list = ListTrait::::fetch(0, numbers_address).expect('List fetch failed'); - assert(numbers_list.address_domain == 0, 'Address domain should be 0'); - assert(numbers_list.len() == 2, 'Length should be 2'); - assert(numbers_list.base.into() == numbers_address, 'Base address mismatch'); + assert_eq!(numbers_list.address_domain, 0, "Address domain should be 0"); + assert_eq!(numbers_list.len(), 2, "Length should be 2"); + assert_eq!(numbers_list.base.into(), numbers_address, "Base address mismatch"); } #[test] @@ -247,9 +247,9 @@ mod tests { fn test_is_empty() { let contract = deploy_mock(); - assert(contract.do_is_empty() == (true, true), 'is empty'); + assert_eq!(contract.do_is_empty(), (true, true), "is empty"); contract.do_append(mock_addr(), 1337); - assert(contract.do_is_empty() == (false, false), 'is not empty'); + assert_eq!(contract.do_is_empty(), (false, false), "is not empty"); } #[test] @@ -257,9 +257,9 @@ mod tests { fn test_append_few() { let contract = deploy_mock(); - assert(contract.do_append(mock_addr(), 10) == (0, 0), '1st append idx'); - assert(contract.do_append(mock_addr(), 20) == (1, 1), '2nd append idx'); - assert(contract.do_get_len() == (2, 2), 'len'); + assert_eq!(contract.do_append(mock_addr(), 10), (0, 0), "1st append idx"); + assert_eq!(contract.do_append(mock_addr(), 20), (1, 1), "2nd append idx"); + assert_eq!(contract.do_get_len(), (2, 2), "len"); } #[test] @@ -282,7 +282,7 @@ mod tests { index += 1; }; - assert(contract.do_get_len() == (max, max), 'len'); + assert_eq!(contract.do_get_len(), (max, max), "len"); // test getting many index = 0; @@ -292,10 +292,10 @@ mod tests { } let (some_addr, some_number) = contract.do_get(index); - assert(some_addr.is_some(), 'addr is some'); - assert(some_addr.unwrap() == mock_addr, 'addr'); - assert(some_number.is_some(), 'number is some'); - assert(some_number.unwrap() == index.into(), 'number'); + assert!(some_addr.is_some(), "addr is some"); + assert_eq!(some_addr.unwrap(), mock_addr, "addr"); + assert!(some_number.is_some(), "number is some"); + assert_eq!(some_number.unwrap(), index.into(), "number"); index += 1; } @@ -312,22 +312,22 @@ mod tests { contract.do_append(mock_addr, 300); // idx 2 let (some_addr0, some_number0) = contract.do_get(0); - assert(some_addr0.is_some(), 'addr0 is some'); - assert(some_addr0.unwrap() == mock_addr, 'addr0'); - assert(some_number0.is_some(), 'number0 is some'); - assert(some_number0.unwrap() == 100, 'number0'); + assert!(some_addr0.is_some(), "addr0 is some"); + assert_eq!(some_addr0.unwrap(), mock_addr, "addr0"); + assert!(some_number0.is_some(), "number0 is some"); + assert_eq!(some_number0.unwrap(), 100, "number0"); let (some_addr1, some_number1) = contract.do_get(1); - assert(some_addr1.is_some(), 'addr1 is some'); - assert(some_addr1.unwrap() == mock_addr, 'addr1'); - assert(some_number1.is_some(), 'number1 is some'); - assert(some_number1.unwrap() == 200, 'number1'); + assert!(some_addr1.is_some(), "addr1 is some"); + assert_eq!(some_addr1.unwrap(), mock_addr, "addr1"); + assert!(some_number1.is_some(), "number1 is some"); + assert_eq!(some_number1.unwrap(), 200, "number1"); let (some_addr2, some_number2) = contract.do_get(2); - assert(some_addr2.is_some(), 'addr2 is some'); - assert(some_addr2.unwrap() == mock_addr, 'addr2'); - assert(some_number2.is_some(), 'number2 is some'); - assert(some_number2.unwrap() == 300, 'number2'); + assert!(some_addr2.is_some(), "addr2 is some"); + assert_eq!(some_addr2.unwrap(), mock_addr, "addr2"); + assert!(some_number2.is_some(), "number2 is some"); + assert_eq!(some_number2.unwrap(), 300, "number2"); } #[test] @@ -335,8 +335,8 @@ mod tests { fn test_get_empty() { let contract = deploy_mock(); let (addr, number) = contract.do_get(0); - assert(addr.is_none(), 'addr is none'); - assert(number.is_none(), 'number is none'); + assert!(addr.is_none(), "addr is none"); + assert!(number.is_none(), "number is none"); } #[test] @@ -345,8 +345,8 @@ mod tests { let contract = deploy_mock(); contract.do_append(mock_addr(), 10); let (addr, number) = contract.do_get(42); - assert(addr.is_none(), 'addr is none'); - assert(number.is_none(), 'number is none'); + assert!(addr.is_none(), "addr is none"); + assert!(number.is_none(), "number is none"); } #[test] @@ -359,9 +359,9 @@ mod tests { contract.do_append(mock_addr, 200); // idx 1 contract.do_append(mock_addr, 300); // idx 2 - assert(contract.do_get_index(0) == (mock_addr, 100), 'idx 0'); - assert(contract.do_get_index(1) == (mock_addr, 200), 'idx 1'); - assert(contract.do_get_index(2) == (mock_addr, 300), 'idx 2'); + assert_eq!(contract.do_get_index(0), (mock_addr, 100), "idx 0"); + assert_eq!(contract.do_get_index(1), (mock_addr, 200), "idx 1"); + assert_eq!(contract.do_get_index(2), (mock_addr, 300), "idx 2"); } #[test] @@ -387,10 +387,10 @@ mod tests { contract.do_set(0, diff_addr, 100); contract.do_set(2, diff_addr, 300); - assert(contract.do_get_index(0) == (diff_addr, 100), 'new at 0'); - assert(contract.do_get_index(1) == (mock_addr, 20), 'old at 1'); - assert(contract.do_get_index(2) == (diff_addr, 300), 'new at 2'); - assert(contract.do_get_len() == (3, 3), 'len'); + assert_eq!(contract.do_get_index(0), (diff_addr, 100), "new at 0"); + assert_eq!(contract.do_get_index(1), (mock_addr, 20), "old at 1"); + assert_eq!(contract.do_get_index(2), (diff_addr, 300), "new at 2"); + assert_eq!(contract.do_get_len(), (3, 3), "len"); } #[test] @@ -411,28 +411,28 @@ mod tests { contract.do_append(mock_addr, 200); // idx 1 contract.do_append(mock_addr, 300); // idx 2 - assert(contract.do_get_len() == (3, 3), 'len'); + assert_eq!(contract.do_get_len(), (3, 3), "len"); let (pop_addr, pop_number) = contract.do_pop_front(); - assert(pop_addr.is_some(), 'pop addr 2 is some'); - assert(pop_addr.unwrap() == mock_addr, 'addr 2'); - assert(pop_number.is_some(), 'pop number 2 is some'); - assert(pop_number.unwrap() == 300, 'number 2'); - assert(contract.do_get_len() == (2, 2), 'len'); + assert!(pop_addr.is_some(), "pop addr 2 is some"); + assert_eq!(pop_addr.unwrap(), mock_addr, "addr 2"); + assert!(pop_number.is_some(), "pop number 2 is some"); + assert_eq!(pop_number.unwrap(), 300, "number 2"); + assert_eq!(contract.do_get_len(), (2, 2), "len"); let (pop_addr, pop_number) = contract.do_pop_front(); - assert(pop_addr.is_some(), 'pop addr 1 is some'); - assert(pop_addr.unwrap() == mock_addr, 'addr 1'); - assert(pop_number.is_some(), 'pop number 1 is some'); - assert(pop_number.unwrap() == 200, 'number 1'); - assert(contract.do_get_len() == (1, 1), 'len'); + assert!(pop_addr.is_some(), "pop addr 1 is some"); + assert_eq!(pop_addr.unwrap(), mock_addr, "addr 1"); + assert!(pop_number.is_some(), "pop number 1 is some"); + assert_eq!(pop_number.unwrap(), 200, "number 1"); + assert_eq!(contract.do_get_len(), (1, 1), "len"); let (pop_addr, pop_number) = contract.do_pop_front(); - assert(pop_addr.is_some(), 'pop addr 0 is some'); - assert(pop_addr.unwrap() == mock_addr, 'addr 0'); - assert(pop_number.is_some(), 'pop number 0 is some'); - assert(pop_number.unwrap() == 100, 'number 0'); - assert(contract.do_get_len() == (0, 0), 'len'); + assert!(pop_addr.is_some(), "pop addr 0 is some"); + assert_eq!(pop_addr.unwrap(), mock_addr, "addr 0"); + assert!(pop_number.is_some(), "pop number 0 is some"); + assert_eq!(pop_number.unwrap(), 100, "number 0"); + assert_eq!(contract.do_get_len(), (0, 0), "len"); } #[test] @@ -441,8 +441,8 @@ mod tests { let contract = deploy_mock(); let (pop_addr, pop_number) = contract.do_pop_front(); - assert(pop_addr.is_none(), 'pop addr none'); - assert(pop_number.is_none(), 'pop number none'); + assert!(pop_addr.is_none(), "pop addr none"); + assert!(pop_number.is_none(), "pop number none"); } #[test] @@ -451,19 +451,19 @@ mod tests { let contract = deploy_mock(); // write something contract.do_append(mock_addr(), 10); - assert(contract.do_get_len() == (1, 1), 'len 1'); + assert_eq!(contract.do_get_len(), (1, 1), "len 1"); // pop it contract.do_pop_front(); - assert(contract.do_get_len() == (0, 0), 'len 2'); + assert_eq!(contract.do_get_len(), (0, 0), "len 2"); let diff_addr = starknet::contract_address_const::<'bye'>(); // append again and check if it overwrites contract.do_append(diff_addr, 9000); - assert(contract.do_get_len() == (1, 1), 'len 3'); + assert_eq!(contract.do_get_len(), (1, 1), "len 3"); let (addr, number) = contract.do_get_index(0); - assert(addr == diff_addr, 'addr'); - assert(number == 9000, 'number'); + assert_eq!(addr, diff_addr, "addr"); + assert_eq!(number, 9000, "number"); } #[test] @@ -478,10 +478,10 @@ mod tests { let (array_addr, array_number) = contract.do_array(); - assert((array_addr.len(), array_number.len()) == contract.do_get_len(), 'lens mismatch'); - assert((*array_addr[0], *array_number[0]) == contract.do_get_index(0), 'idx 0'); - assert((*array_addr[1], *array_number[1]) == contract.do_get_index(1), 'idx 1'); - assert((*array_addr[2], *array_number[2]) == contract.do_get_index(2), 'idx 2'); + assert_eq!((array_addr.len(), array_number.len()), contract.do_get_len(), "lens mismatch"); + assert_eq!((*array_addr[0], *array_number[0]), contract.do_get_index(0), "idx 0"); + assert_eq!((*array_addr[1], *array_number[1]), contract.do_get_index(1), "idx 1"); + assert_eq!((*array_addr[2], *array_number[2]), contract.do_get_index(2), "idx 2"); } #[test] @@ -490,7 +490,7 @@ mod tests { let contract = deploy_mock(); let (array_addr, array_number) = contract.do_array(); - assert((array_addr.len(), array_number.len()) == (0, 0), 'lens must be null'); + assert_eq!((array_addr.len(), array_number.len()), (0, 0), "lens must be null"); } #[test] @@ -503,7 +503,7 @@ mod tests { contract.do_append(mock_addr, 200); // idx 1 contract.do_append(mock_addr, 300); // idx 2 contract.do_clean(); - assert(contract.do_get_len() == (0, 0), 'is empty'); + assert_eq!(contract.do_get_len(), (0, 0), "is empty"); } #[test] @@ -511,11 +511,11 @@ mod tests { fn test_array_clean_with_empty_array() { let contract = deploy_mock(); - assert(contract.do_get_len() == (0, 0), 'is empty'); + assert_eq!(contract.do_get_len(), (0, 0), "is empty"); contract.do_clean(); - assert(contract.do_get_len() == (0, 0), 'is still empty'); + assert_eq!(contract.do_get_len(), (0, 0), "is still empty"); } #[test] @@ -526,18 +526,18 @@ mod tests { contract.do_append(mock_addr, 100); // idx 0 let (addr, number) = contract.do_get(0); - assert(addr.is_some(), 'addr is some'); - assert(addr.unwrap() == mock_addr, 'should be mock_addr'); - assert(number.is_some(), 'number is some'); - assert(number.unwrap() == 100, 'should be 100'); + assert!(addr.is_some(), "addr is some"); + assert_eq!(addr.unwrap(), mock_addr, "should be mock_addr"); + assert!(number.is_some(), "number is some"); + assert_eq!(number.unwrap(), 100, "should be 100"); contract.do_clean(); - assert(contract.do_get_len() == (0, 0), 'len'); + assert_eq!(contract.do_get_len(), (0, 0), "len"); let (addr, number) = contract.do_get(0); - assert(addr.is_none(), 'addr is none'); - assert(number.is_none(), 'number is none'); + assert!(addr.is_none(), "addr is none"); + assert!(number.is_none(), "number is none"); } #[test] @@ -546,7 +546,7 @@ mod tests { let contract = deploy_mock(); contract.do_append_span(array![], array![]); - assert(contract.do_is_empty() == (true, true), 'should be empty'); + assert_eq!(contract.do_is_empty(), (true, true), "should be empty"); } #[test] @@ -555,18 +555,18 @@ mod tests { let contract = deploy_mock(); let mock_addr = mock_addr(); - assert(contract.do_append(mock_addr, 10) == (0, 0), '1st append idx'); - assert(contract.do_append(mock_addr, 20) == (1, 1), '2nd append idx'); - assert(contract.do_get_len() == (2, 2), 'len'); - assert(contract.do_get_index(0) == (mock_addr, 10), 'idx 0'); - assert(contract.do_get_index(1) == (mock_addr, 20), 'idx 1'); + assert_eq!(contract.do_append(mock_addr, 10), (0, 0), "1st append idx"); + assert_eq!(contract.do_append(mock_addr, 20), (1, 1), "2nd append idx"); + assert_eq!(contract.do_get_len(), (2, 2), "len"); + assert_eq!(contract.do_get_index(0), (mock_addr, 10), "idx 0"); + assert_eq!(contract.do_get_index(1), (mock_addr, 20), "idx 1"); contract.do_append_span(array![mock_addr], array![30]); let (a, b) = contract.do_get_len(); - assert((a, b) == (3, 3), 'len'); + assert_eq!((a, b), (3, 3), "len"); - assert(contract.do_get_index(0) == (mock_addr, 10), 'idx 0'); - assert(contract.do_get_index(1) == (mock_addr, 20), 'idx 1'); - assert(contract.do_get_index(2) == (mock_addr, 30), 'idx 2'); + assert_eq!(contract.do_get_index(0), (mock_addr, 10), "idx 0"); + assert_eq!(contract.do_get_index(1), (mock_addr, 20), "idx 1"); + assert_eq!(contract.do_get_index(2), (mock_addr, 30), "idx 2"); } }