Skip to content

Commit

Permalink
refactor(tests): use less redundant names
Browse files Browse the repository at this point in the history
Also, decrease tests' visibility to necessary minimum.
  • Loading branch information
jan-ferdinand committed Oct 9, 2023
1 parent 794073b commit 8a0b667
Show file tree
Hide file tree
Showing 27 changed files with 200 additions and 216 deletions.
2 changes: 1 addition & 1 deletion triton-vm/src/aet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl AlgebraicExecutionTrace {
}

#[cfg(test)]
mod test {
mod tests {
use crate::triton_asm;
use crate::triton_program;
use twenty_first::shared_math::b_field_element::BFIELD_ONE;
Expand Down
4 changes: 2 additions & 2 deletions triton-vm/src/arithmetic_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl ArithmeticDomain {
}

#[cfg(test)]
mod domain_tests {
mod tests {
use itertools::Itertools;
use twenty_first::shared_math::b_field_element::BFieldElement;
use twenty_first::shared_math::traits::PrimitiveRootOfUnity;
Expand Down Expand Up @@ -188,7 +188,7 @@ mod domain_tests {
}

#[test]
fn domain_values_test() {
fn domain_values() {
let x_cubed_coefficients = [0, 0, 0, 1].map(BFieldElement::new).to_vec();
let poly = Polynomial::new(x_cubed_coefficients.clone());

Expand Down
22 changes: 11 additions & 11 deletions triton-vm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,42 +64,42 @@ mod tests {

#[test]
#[should_panic(expected = "Instruction pointer 1 points outside of program")]
fn test_vm_err() {
fn vm_err() {
let program = triton_program!(nop);
program.run([].into(), [].into()).unwrap();
}

#[test]
#[should_panic(expected = "Operational stack is too shallow")]
fn shrink_op_stack_too_much_test() {
fn shrink_op_stack_too_much() {
let program = triton_program!(pop halt);
program.run([].into(), [].into()).unwrap();
}

#[test]
#[should_panic(expected = "Jump stack is empty.")]
fn return_without_call_test() {
fn return_without_call() {
let program = triton_program!(return halt);
program.run([].into(), [].into()).unwrap();
}

#[test]
#[should_panic(expected = "Jump stack is empty.")]
fn recurse_without_call_test() {
fn recurse_without_call() {
let program = triton_program!(recurse halt);
program.run([].into(), [].into()).unwrap();
}

#[test]
#[should_panic(expected = "Assertion failed: st0 must be 1. ip: 2, clk: 1, st0: 0")]
fn assert_false_test() {
fn assert_false() {
let program = triton_program!(push 0 assert halt);
program.run([].into(), [].into()).unwrap();
}

proptest! {
#[test]
fn assert_unequal_vec_test(
fn assert_unequal_vec(
test_vector in arb::<[BFieldElement; DIGEST_LENGTH]>(),
disturbance_index in 0..DIGEST_LENGTH,
random_element in arb::<BFieldElement>(),
Expand Down Expand Up @@ -141,35 +141,35 @@ mod tests {

#[test]
#[should_panic(expected = "0 does not have a multiplicative inverse")]
fn inverse_of_zero_test() {
fn inverse_of_zero() {
let program = triton_program!(push 0 invert halt);
program.run([].into(), [].into()).unwrap();
}

#[test]
#[should_panic(expected = "0 does not have a multiplicative inverse")]
fn xfe_inverse_of_zero_test() {
fn xfe_inverse_of_zero() {
let program = triton_program!(push 0 push 0 push 0 xinvert halt);
program.run([].into(), [].into()).unwrap();
}

#[test]
#[should_panic(expected = "Division by 0 is impossible")]
fn division_by_zero_test() {
fn division_by_zero() {
let program = triton_program!(push 0 push 5 div_mod halt);
program.run([].into(), [].into()).unwrap();
}

#[test]
#[should_panic(expected = "The logarithm of 0 does not exist")]
fn log_of_zero_test() {
fn log_of_zero() {
let program = triton_program!(push 0 log_2_floor halt);
program.run([].into(), [].into()).unwrap();
}

#[test]
#[should_panic(expected = "Failed to convert BFieldElement 4294967297 into u32")]
fn failed_u32_conversion_test() {
fn failed_u32_conversion() {
let program = triton_program!(push 4294967297 push 1 and halt);
program.run([].into(), [].into()).unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion triton-vm/src/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ mod tests {

proptest! {
#[test]
fn sample_indices_test(
fn sample_indices(
fri in arbitrary_fri(),
initial_absorb in arbitrary_element_to_absorb(),
) {
Expand Down
14 changes: 7 additions & 7 deletions triton-vm/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ impl TryFrom<usize> for InstructionBit {
}

#[cfg(test)]
mod instruction_tests {
mod tests {
use std::cmp::Ordering;
use std::collections::HashMap;

Expand All @@ -620,7 +620,7 @@ mod instruction_tests {
use crate::op_stack::NUM_OP_STACK_REGISTERS;
use crate::triton_asm;
use crate::triton_program;
use crate::vm::triton_vm_tests::test_program_for_call_recurse_return;
use crate::vm::tests::test_program_for_call_recurse_return;
use crate::NonDeterminism;
use crate::Program;

Expand Down Expand Up @@ -648,7 +648,7 @@ mod instruction_tests {
}

#[test]
fn parse_push_pop_test() {
fn parse_push_pop() {
let program = triton_program!(push 1 push 1 add pop);
let instructions = program.into_iter().collect_vec();
let expected = vec![
Expand All @@ -663,7 +663,7 @@ mod instruction_tests {

#[test]
#[should_panic(expected = "Duplicate label: foo")]
fn fail_on_duplicate_labels_test() {
fn fail_on_duplicate_labels() {
triton_program!(
push 2
call foo
Expand All @@ -675,7 +675,7 @@ mod instruction_tests {
}

#[test]
fn ib_registers_are_binary_test() {
fn ib_registers_are_binary() {
for instruction in ALL_INSTRUCTIONS {
for instruction_bit in InstructionBit::iter() {
let ib_value = instruction.ib(instruction_bit);
Expand All @@ -685,7 +685,7 @@ mod instruction_tests {
}

#[test]
fn instruction_to_opcode_to_instruction_is_consistent_test() {
fn instruction_to_opcode_to_instruction_is_consistent() {
for instr in ALL_INSTRUCTIONS {
assert_eq!(instr, instr.opcode().try_into().unwrap());
}
Expand All @@ -700,7 +700,7 @@ mod instruction_tests {

#[test]
/// Serves no other purpose than to increase code coverage results.
fn run_constant_methods_test() {
fn run_constant_methods() {
all_instructions_without_args();
all_instruction_names();
}
Expand Down
11 changes: 4 additions & 7 deletions triton-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +511,17 @@ pub fn verify(parameters: StarkParameters, claim: &Claim, proof: &Proof) -> bool
}

#[cfg(test)]
mod public_interface_tests {
mod tests {
use rand::thread_rng;
use rand::Rng;

use crate::shared_tests::create_proofs_directory;
use crate::shared_tests::load_proof;
use crate::shared_tests::proof_file_exists;
use crate::shared_tests::save_proof;
use crate::shared_tests::*;
use crate::stark::StarkHasher;

use super::*;

#[test]
pub fn lockscript_test() {
fn lockscript() {
// Program proves the knowledge of a hash preimage
let program = triton_program!(
divine divine divine divine divine
Expand Down Expand Up @@ -614,7 +611,7 @@ mod public_interface_tests {
}

#[test]
fn save_proof_to_and_load_from_disk_test() {
fn save_proof_to_and_load_from_disk() {
let filename = "nop_halt.tsp";
if !proof_file_exists(filename) {
create_proofs_directory().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions triton-vm/src/op_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@ impl From<&OpStackElement> for BFieldElement {
}

#[cfg(test)]
mod op_stack_test {
mod tests {
use twenty_first::shared_math::b_field_element::BFieldElement;

use crate::op_stack::OpStack;
use crate::op_stack::OpStackElement;

#[test]
fn sanity_test() {
fn sanity() {
let digest = Default::default();
let mut op_stack = OpStack::new(digest);

Expand Down
22 changes: 11 additions & 11 deletions triton-vm/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ fn token1<'a>(token: &'a str) -> impl Fn(&'a str) -> ParseResult<()> {
}

#[cfg(test)]
pub mod parser_tests {
pub(crate) mod tests {
use itertools::Itertools;
use rand::distributions::WeightedIndex;
use rand::prelude::*;
Expand Down Expand Up @@ -695,7 +695,7 @@ pub mod parser_tests {
}

#[test]
fn parse_program_empty_test() {
fn parse_program_empty() {
parse_program_prop(TestCase {
input: "",
expected: Program::new(&[]),
Expand Down Expand Up @@ -761,7 +761,7 @@ pub mod parser_tests {
}

#[test]
fn parse_program_whitespace_test() {
fn parse_program_whitespace() {
parse_program_neg_prop(NegativeTestCase {
input: "poppop",
expected_error: "n/a",
Expand Down Expand Up @@ -813,7 +813,7 @@ pub mod parser_tests {
}

#[test]
fn parse_program_label_test() {
fn parse_program_label() {
parse_program_prop(TestCase {
input: "foo: call foo",
expected: Program::new(&[
Expand Down Expand Up @@ -876,7 +876,7 @@ pub mod parser_tests {
}

#[test]
fn parse_program_nonexistent_instructions_test() {
fn parse_program_nonexistent_instructions() {
parse_program_neg_prop(NegativeTestCase {
input: "swap 0",
expected_error: "instruction `swap` cannot take argument `0`",
Expand All @@ -900,7 +900,7 @@ pub mod parser_tests {
}

#[test]
fn parse_program_bracket_syntax_test() {
fn parse_program_bracket_syntax() {
parse_program_prop(TestCase {
input: "foo: [foo]",
expected: Program::new(&[
Expand All @@ -919,7 +919,7 @@ pub mod parser_tests {
}

#[test]
fn parse_program_test() {
fn parse_program() {
for size in 0..100 {
let code = program_gen(size * 10);

Expand Down Expand Up @@ -1031,20 +1031,20 @@ pub mod parser_tests {
}

#[test]
fn test_triton_instruction_macro_on_simple_instructions() {
fn triton_instruction_macro_parses_simple_instructions() {
assert_eq!(Instruction(Halt), triton_instr!(halt));
assert_eq!(Instruction(Add), triton_instr!(add));
assert_eq!(Instruction(Pop), triton_instr!(pop));
}

#[test]
#[should_panic(expected = "not_an_instruction")]
fn negative_test_of_triton_instruction_macro() {
fn triton_instruction_macro_fails_when_encountering_unknown_instruction() {
triton_instr!(not_an_instruction);
}

#[test]
fn test_triton_instruction_macro_on_instructions_with_argument() {
fn triton_instruction_macro_parses_instructions_with_argument() {
assert_eq!(Instruction(Push(7_u64.into())), triton_instr!(push 7));
assert_eq!(Instruction(Dup(ST3)), triton_instr!(dup 3));
assert_eq!(Instruction(Swap(ST5)), triton_instr!(swap 5));
Expand All @@ -1055,7 +1055,7 @@ pub mod parser_tests {
}

#[test]
fn test_triton_asm_macro_repeating_one_instruction() {
fn triton_asm_macro_can_repeat_instructions() {
let instructions = triton_asm![push 42; 3];
let expected_instructions = vec![Instruction(Push(42_u64.into())); 3];
assert_eq!(expected_instructions, instructions);
Expand Down
2 changes: 1 addition & 1 deletion triton-vm/src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ macro_rules! prof_itr0 {
pub(crate) use prof_itr0;

#[cfg(test)]
pub mod triton_profiler_tests {
mod tests {
use std::thread::sleep;
use std::time::Duration;

Expand Down
4 changes: 2 additions & 2 deletions triton-vm/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,14 @@ where
}

#[cfg(test)]
mod test {
mod tests {
use itertools::Itertools;
use rand::thread_rng;
use rand::Rng;
use twenty_first::shared_math::tip5::Tip5;

use crate::example_programs::calculate_new_mmr_peaks_from_append_with_safe_lists;
use crate::parser::parser_tests::program_gen;
use crate::parser::tests::program_gen;
use crate::triton_asm;
use crate::triton_program;

Expand Down
6 changes: 3 additions & 3 deletions triton-vm/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Claim {
}

#[cfg(test)]
pub mod test_claim_proof {
mod tests {
use proptest::collection::vec;
use proptest::prelude::*;
use rand::random;
Expand All @@ -82,7 +82,7 @@ pub mod test_claim_proof {
use super::*;

#[test]
fn test_decode_proof() {
fn decode_proof() {
let data: Vec<BFieldElement> = random_elements(348);
let proof = Proof(data);

Expand All @@ -93,7 +93,7 @@ pub mod test_claim_proof {
}

#[test]
fn test_decode_claim() {
fn decode_claim() {
let claim = Claim {
program_digest: random(),
input: random_elements(346),
Expand Down
Loading

0 comments on commit 8a0b667

Please sign in to comment.