From 07c38773af7cda6b1bbd5104f37a4f471492127e Mon Sep 17 00:00:00 2001 From: msaug Date: Wed, 4 Oct 2023 12:34:08 +0700 Subject: [PATCH] tests: StorageBaseAddress partialEq --- crates/utils/src/helpers.cairo | 13 +++++++------ crates/utils/src/tests/test_traits.cairo | 23 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/utils/src/helpers.cairo b/crates/utils/src/helpers.cairo index cdef746a5..c3d2d0997 100644 --- a/crates/utils/src/helpers.cairo +++ b/crates/utils/src/helpers.cairo @@ -494,13 +494,14 @@ impl SpanExtension, +Drop> of SpanExtensionTrait { // Returns true if the array contains an item. fn contains<+PartialEq>(mut self: Span, value: T) -> bool { loop { - if self.len() == 0 { - break false; + match self.pop_front(){ + Option::Some(elem) => { + if *elem == value { + break true; + } + }, + Option::None => {} } - let elem = *self.pop_front().unwrap(); - if elem == value { - break true; - }; } } } diff --git a/crates/utils/src/tests/test_traits.cairo b/crates/utils/src/tests/test_traits.cairo index d2073e336..c6e744309 100644 --- a/crates/utils/src/tests/test_traits.cairo +++ b/crates/utils/src/tests/test_traits.cairo @@ -1,5 +1,9 @@ -use utils::traits::Felt252TryIntoStorageBaseAddress; -use starknet::{StorageBaseAddress, StorageAddress, storage_address_from_base}; +use utils::traits::{StorageBaseAddressPartialEq, Felt252TryIntoStorageBaseAddress}; +use starknet::{ + StorageBaseAddress, StorageAddress, storage_address_from_base, storage_address_try_from_felt252, + storage_base_address_from_felt252 +}; +use test::test_utils::{assert_eq, assert_ne}; #[test] fn test_storage_base_address_try_into_felt252() { @@ -14,3 +18,18 @@ fn test_storage_base_address_try_into_felt252() { let res: Option = ABOVE_MAX.try_into(); assert(res.is_none(), 'expected conversion failure'); } + +#[test] +fn test_eq_storage_base_address() { + let val_1 = storage_base_address_from_felt252(0x01); + + assert_eq(@val_1, @val_1, 'expected equality') +} + +#[test] +fn test_ne_storage_base_address() { + let val_1 = storage_base_address_from_felt252(0x01); + let val_2 = storage_base_address_from_felt252(0x02); + + assert_ne(@val_1, @val_2, 'expected inequality') +}