Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Commit

Permalink
Fix mutant count output
Browse files Browse the repository at this point in the history
  • Loading branch information
lwagner94 committed Apr 5, 2022
1 parent c049654 commit 29146f7
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,62 @@ impl MutationEngine {
let mutations = module.instruction_walker::<MutationLocation>(callback)?;

// TODO: Fix count - we only count MutationLocation, not all Mutations
log::info!("Generated {} mutations", mutations.len());
log::info!("Generated {} mutations", count_mutants(&mutations));
Ok(mutations)
}
}

fn count_mutants(locations: &[MutationLocation]) -> i32 {
locations
.iter()
.fold(0, |acc, loc| acc + loc.mutations.len() as i32)
}

#[cfg(test)]
mod tests {
use crate::operator::ops::BinaryOperatorMulToDivS;

use super::*;
use anyhow::Result;
use parity_wasm::elements::Instruction;

#[test]
fn test_count_mutants() {
assert_eq!(count_mutants(&[]), 0);

let m = Mutation {
id: 1234,
operator: Box::new(BinaryOperatorMulToDivS::new(&Instruction::I32Mul).unwrap()),
};

assert_eq!(
count_mutants(&[MutationLocation {
function_number: 1,
statement_number: 1,
offset: 1337,
mutations: vec![m.clone(); 2],
}]),
2
);

assert_eq!(
count_mutants(&[
MutationLocation {
function_number: 1,
statement_number: 1,
offset: 1337,
mutations: vec![m.clone(); 2],
},
MutationLocation {
function_number: 1,
statement_number: 1,
offset: 1337,
mutations: vec![m; 2],
},
]),
4
);
}

#[test]
fn test_discover_mutation_positions() -> Result<()> {
Expand Down

0 comments on commit 29146f7

Please sign in to comment.