Skip to content

Commit

Permalink
Amoeba piece: 100% test coverage (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshOrndorff authored Apr 19, 2024
1 parent e0c4dc7 commit 5c861d9
Showing 1 changed file with 104 additions and 2 deletions.
106 changes: 104 additions & 2 deletions wardrobe/amoeba/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ fn creation_with_inputs_fails() {
);
}

#[test]
fn creation_with_evictions_fails() {
let example = AmoebaDetails {
generation: 0,
four_bytes: *b"test",
};
let evicted_input_data = vec![example.clone().into()];
let output_data = vec![example.into()];

assert_eq!(
AmoebaCreation.check(&[], &evicted_input_data, &[], &output_data),
Err(ConstraintCheckerError::NoEvictionsAllowed),
);
}

#[test]
fn creation_with_badly_typed_output_fails() {
let input_data = Vec::new();
Expand Down Expand Up @@ -109,7 +124,31 @@ fn mitosis_valid_transaction_works() {
}

#[test]
fn mitosis_wrong_generation() {
fn mitosis_with_evictions_fails() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
};
let d1 = AmoebaDetails {
generation: 2,
four_bytes: *b"test",
};
let d2 = AmoebaDetails {
generation: 2,
four_bytes: *b"test",
};
let input_data = vec![mother.clone().into()];
let evicted_input_data = vec![mother.into()];
let output_data = vec![d1.into(), d2.into()];

assert_eq!(
AmoebaMitosis.check(&input_data, &evicted_input_data, &[], &output_data),
Err(ConstraintCheckerError::NoEvictionsAllowed)
);
}

#[test]
fn mitosis_wrong_generation_first_daughter() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
Expand All @@ -131,6 +170,29 @@ fn mitosis_wrong_generation() {
);
}

#[test]
fn mitosis_wrong_generation_second_daughter() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
};
let d1 = AmoebaDetails {
generation: 2,
four_bytes: *b"test",
};
let d2 = AmoebaDetails {
generation: 3, // This daughter has the wrong generation
four_bytes: *b"test",
};
let input_data = vec![mother.into()];
let output_data = vec![d1.into(), d2.into()];

assert_eq!(
AmoebaMitosis.check(&input_data, &[], &[], &output_data),
Err(ConstraintCheckerError::WrongGeneration),
);
}

#[test]
fn mitosis_badly_typed_input() {
let mother = Bogus;
Expand Down Expand Up @@ -171,7 +233,27 @@ fn mitosis_no_input() {
}

#[test]
fn mitosis_badly_typed_output() {
fn mitosis_badly_typed_first_daughter() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
};
let d1 = Bogus;
let d2 = AmoebaDetails {
generation: 2,
four_bytes: *b"test",
};
let input_data = vec![mother.into()];
let output_data = vec![d1.into(), d2.into()];

assert_eq!(
AmoebaMitosis.check(&input_data, &[], &[], &output_data),
Err(ConstraintCheckerError::BadlyTypedOutput),
);
}

#[test]
fn mitosis_badly_typed_second_daughter() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
Expand Down Expand Up @@ -264,6 +346,26 @@ fn death_no_input() {
);
}

#[test]
fn death_eviction_not_allowed() {
let a1 = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
};
let a2 = AmoebaDetails {
generation: 4,
four_bytes: *b"test",
};
let input_data = vec![a1.into()];
let evicted_input_data = vec![a2.into()];
let output_data = vec![];

assert_eq!(
AmoebaDeath.check(&input_data, &evicted_input_data, &[], &output_data),
Err(ConstraintCheckerError::NoEvictionsAllowed),
);
}

#[test]
fn death_multiple_inputs() {
let a1 = AmoebaDetails {
Expand Down

0 comments on commit 5c861d9

Please sign in to comment.