Skip to content

Commit

Permalink
tests: StorageBaseAddress partialEq
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Oct 4, 2023
1 parent c7d9492 commit 07c3877
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
13 changes: 7 additions & 6 deletions crates/utils/src/helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,14 @@ impl SpanExtension<T, +Copy<T>, +Drop<T>> of SpanExtensionTrait<T> {
// Returns true if the array contains an item.
fn contains<+PartialEq<T>>(mut self: Span<T>, 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;
};
}
}
}
Expand Down
23 changes: 21 additions & 2 deletions crates/utils/src/tests/test_traits.cairo
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -14,3 +18,18 @@ fn test_storage_base_address_try_into_felt252() {
let res: Option<StorageBaseAddress> = 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')
}

0 comments on commit 07c3877

Please sign in to comment.