Skip to content

Commit

Permalink
StorageVec Precondition Tests (#4335)
Browse files Browse the repository at this point in the history
## Description

Adds precondition checks to storage vector tests.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: Braqzen <[email protected]>
  • Loading branch information
3 people authored Mar 24, 2023
1 parent dfc0b07 commit adc5c1a
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions test/src/sdk-harness/test_projects/storage_vec/testgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ macro_rules! testgen {
push(&instance, $arg0).await;

assert_eq!(len(&instance).await, 1);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(pop(&instance).await, $arg0);
assert_eq!(len(&instance).await, 0);
}
Expand All @@ -259,6 +260,12 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
assert_eq!(get(&instance, 3).await, $arg3);

assert_eq!(remove(&instance, 2).await, $arg2);

assert_eq!(len(&instance).await, 3);
Expand All @@ -276,6 +283,12 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
assert_eq!(get(&instance, 3).await, $arg3);

assert_eq!(swap_remove(&instance, 1).await, $arg1);

assert_eq!(len(&instance).await, 3);
Expand All @@ -293,6 +306,12 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
assert_eq!(get(&instance, 3).await, $arg3);

set(&instance, 0, $arg3).await;
set(&instance, 1, $arg2).await;
set(&instance, 2, $arg1).await;
Expand All @@ -317,6 +336,12 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
assert_eq!(get(&instance, 3).await, $arg3);

insert(&instance, 1, $arg4).await;

assert_eq!(len(&instance).await, 5);
Expand Down Expand Up @@ -363,6 +388,8 @@ macro_rules! testgen {

push(&instance, $arg0).await;

assert!(!is_empty(&instance).await);

clear(&instance).await;

assert!(is_empty(&instance).await);
Expand All @@ -372,6 +399,8 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert!(!is_empty(&instance).await);

clear(&instance).await;

assert!(is_empty(&instance).await);
Expand All @@ -386,6 +415,11 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
assert_eq!(get(&instance, 3).await, $arg3);
swap(&instance, 0, 3).await;
swap(&instance, 1, 2).await;

Expand All @@ -402,6 +436,10 @@ macro_rules! testgen {
push(&instance, $arg0).await;
push(&instance, $arg1).await;

assert_eq!(len(&instance).await, 2);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);

assert_eq!(first(&instance).await, $arg0);
}

Expand All @@ -412,6 +450,9 @@ macro_rules! testgen {
push(&instance, $arg0).await;
push(&instance, $arg1).await;

assert_eq!(len(&instance).await, 2);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(last(&instance).await, $arg1);
}

Expand All @@ -424,15 +465,23 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
assert_eq!(get(&instance, 3).await, $arg3);

reverse(&instance).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg3);
assert_eq!(get(&instance, 1).await, $arg2);
assert_eq!(get(&instance, 2).await, $arg1);
assert_eq!(get(&instance, 3).await, $arg0);

reverse(&instance).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
Expand All @@ -447,14 +496,22 @@ macro_rules! testgen {
push(&instance, $arg1).await;
push(&instance, $arg2).await;

assert_eq!(len(&instance).await, 3);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);

reverse(&instance).await;

assert_eq!(len(&instance).await, 3);

assert_eq!(get(&instance, 0).await, $arg2);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg0);

reverse(&instance).await;

assert_eq!(len(&instance).await, 3);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
Expand All @@ -469,8 +526,15 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
assert_eq!(get(&instance, 3).await, $arg3);

fill(&instance, $arg4).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg4);
assert_eq!(get(&instance, 1).await, $arg4);
assert_eq!(get(&instance, 2).await, $arg4);
Expand All @@ -486,6 +550,12 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
assert_eq!(get(&instance, 3).await, $arg3);

resize(&instance, 6, $arg4).await;

assert_eq!(len(&instance).await, 6);
Expand All @@ -506,6 +576,12 @@ macro_rules! testgen {
push(&instance, $arg2).await;
push(&instance, $arg3).await;

assert_eq!(len(&instance).await, 4);
assert_eq!(get(&instance, 0).await, $arg0);
assert_eq!(get(&instance, 1).await, $arg1);
assert_eq!(get(&instance, 2).await, $arg2);
assert_eq!(get(&instance, 3).await, $arg3);

resize(&instance, 2, $arg4).await;

assert_eq!(len(&instance).await, 2);
Expand Down

0 comments on commit adc5c1a

Please sign in to comment.