Skip to content

Commit

Permalink
test(unit_tests): improves coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ynn committed Oct 21, 2024
1 parent 58c14e5 commit 31955ee
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Some important implementation details:

### 4.1 Unit Tests

Many unit tests are written.
Many unit tests are written. The coverage is around 80%.

### 4.2 Integration Tests

Expand Down
30 changes: 30 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,33 @@ impl Args {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
// #[ignore]
fn test01() {
let mut args = Args {
image_file: String::new(),
codel_size: None,
fall_back_to_white: false,
fall_back_to_black: false,
max_iter: None,
verbose: false,
};
assert!(args.validate().is_ok());

args.fall_back_to_white = true;
assert!(args.validate().is_ok());

args.fall_back_to_white = false;
args.fall_back_to_black = true;
assert!(args.validate().is_ok());

args.fall_back_to_white = true;
args.fall_back_to_black = true;
assert!(args.validate().is_err());
}
}
11 changes: 11 additions & 0 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ mod tests {
];
let s = FxHashSet::from_iter(l);
let block = Block::new(&s);

assert_eq!(block.size, 19);

assert_eq!(block.right_left, (1, 5));
assert_eq!(block.right_right, (3, 5));
assert_eq!(block.down_left, (4, 3));
Expand All @@ -126,5 +128,14 @@ mod tests {
assert_eq!(block.left_right, (1, 0));
assert_eq!(block.up_left, (0, 1));
assert_eq!(block.up_right, (0, 3));

assert_eq!((1, 5), block.get_corner_index(&DP::Right, &CC::Left));
assert_eq!((3, 5), block.get_corner_index(&DP::Right, &CC::Right));
assert_eq!((4, 3), block.get_corner_index(&DP::Down, &CC::Left));
assert_eq!((4, 1), block.get_corner_index(&DP::Down, &CC::Right));
assert_eq!((3, 0), block.get_corner_index(&DP::Left, &CC::Left));
assert_eq!((1, 0), block.get_corner_index(&DP::Left, &CC::Right));
assert_eq!((0, 1), block.get_corner_index(&DP::Up, &CC::Left));
assert_eq!((0, 3), block.get_corner_index(&DP::Up, &CC::Right));
}
}
6 changes: 6 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,12 @@ mod tests {
fn test_roll_01() {
let command = Command::Roll;

//the length of stack is insufficient
let mut ip = Interpreter::new();
ip.stack = vec![9];
command.execute(&mut ip, 1);
assert_eq!(vec![9], ip.stack);

//negative depth
let mut ip = Interpreter::new();
ip.stack = vec![9, 8, 7, 1, 2, 3, 4, -2, 5];
Expand Down
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,22 @@ pub fn run(args: &Args) -> Result<(), Box<dyn Error>> {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
// #[ignore]
fn test01() {
let args = Args {
image_file: "./test_images/coverage.png".to_string(),
codel_size: None,
fall_back_to_white: true,
fall_back_to_black: false,
max_iter: None,
verbose: false,
};
assert!(run(&args).is_ok());
}
}
2 changes: 1 addition & 1 deletion src/stdin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ mod tests {
assert_eq!(Some('あ'), stdin.read_char());
assert_eq!(Some('a'), stdin.read_char());
assert_eq!(Some('a'), stdin.read_char());
assert_eq!(Some('あ'), stdin.read_char());
assert_eq!(Some("あ".to_owned()), stdin.read_word());
assert_eq!(None, stdin.read_char());
assert_eq!(None, stdin.read_word());
}
Expand Down
Binary file added test_images/coverage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 31955ee

Please sign in to comment.