Skip to content

Commit

Permalink
better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ethteck committed Dec 5, 2023
1 parent c6fc90a commit 0b4360c
Show file tree
Hide file tree
Showing 23 changed files with 310 additions and 21 deletions.
229 changes: 229 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ license = "MIT"

[dependencies]
clap = { version = "4.4.10", features = ["derive"] }
thiserror = "1.0"
thiserror = "1.0"

[dev-dependencies]
rstest = "0.18.2"
52 changes: 38 additions & 14 deletions src/yay0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,37 +228,61 @@ fn search(

#[cfg(test)]
mod tests {
#[test]
fn test_matching_decompression() {
let compressed_file = include_bytes!("../test_data/1.Yay0");
let decompressed_file = include_bytes!("../test_data/1.bin");
use core::panic;
use rstest::rstest;
use std::{
fs::File,
io::{BufReader, Read},
path::PathBuf,
};

pub fn read_test_file(path: PathBuf) -> Vec<u8> {
let file = match File::open(path) {
Ok(file) => file,
Err(_error) => {
panic!("Failed to open file");
}
};

let mut buf_reader = BufReader::new(file);
let mut buffer = Vec::new();

let _ = buf_reader.read_to_end(&mut buffer);

buffer
}

#[rstest]
fn test_matching_decompression(#[files("test_data/*.Yay0")] path: PathBuf) {
let compressed_file = &read_test_file(path.clone());
let decompressed_file = &read_test_file(path.with_extension(""));

let decompressed: Box<[u8]> = super::decompress_yay0(compressed_file);
assert_eq!(decompressed_file, decompressed.as_ref());
}

#[test]
fn test_matching_compression() {
let compressed_file = include_bytes!("../test_data/1.Yay0");
let decompressed_file = include_bytes!("../test_data/1.bin");
#[rstest]
fn test_matching_compression(#[files("test_data/*.Yay0")] path: PathBuf) {
let compressed_file = &read_test_file(path.clone());
let decompressed_file = &read_test_file(path.with_extension(""));

let compressed = super::compress_yay0(decompressed_file.as_slice());
assert_eq!(compressed_file, compressed.as_ref());
}

#[test]
fn test_cycle_decompressed() {
let decompressed_file = include_bytes!("../test_data/1.bin");
#[rstest]
fn test_cycle_decompressed(#[files("test_data/*.Yay0")] path: PathBuf) {
let decompressed_file = &read_test_file(path.with_extension(""));

assert_eq!(
decompressed_file,
super::decompress_yay0(&super::compress_yay0(decompressed_file.as_ref())).as_ref()
);
}

#[test]
fn test_cycle_compressed() {
let compressed_file = include_bytes!("../test_data/1.Yay0");
#[rstest]
fn test_cycle_compressed(#[files("test_data/*.Yay0")] path: PathBuf) {
let compressed_file = &read_test_file(path);

assert_eq!(
compressed_file,
Expand Down
12 changes: 6 additions & 6 deletions src/yaz0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,25 +238,25 @@ fn search(
mod tests {
#[test]
fn test_matching_decompression() {
let compressed_file = include_bytes!("../test_data/1.Yaz0");
let decompressed_file = include_bytes!("../test_data/1.bin");
let compressed_file = include_bytes!("../test_data/small.txt.Yaz0");
let decompressed_file = include_bytes!("../test_data/small.txt");

let decompressed: Box<[u8]> = super::decompress_yaz0(compressed_file);
assert_eq!(decompressed_file, decompressed.as_ref());
}

#[test]
fn test_matching_compression() {
let compressed_file = include_bytes!("../test_data/1.Yaz0");
let decompressed_file = include_bytes!("../test_data/1.bin");
let compressed_file = include_bytes!("../test_data/small.txt.Yaz0");
let decompressed_file = include_bytes!("../test_data/small.txt");

let compressed = super::compress_yaz0(decompressed_file.as_slice());
assert_eq!(compressed_file, compressed.as_ref());
}

#[test]
fn test_cycle_decompressed() {
let decompressed_file = include_bytes!("../test_data/1.bin");
let decompressed_file = include_bytes!("../test_data/small.txt");

assert_eq!(
decompressed_file,
Expand All @@ -266,7 +266,7 @@ mod tests {

#[test]
fn test_cycle_compressed() {
let compressed_file = include_bytes!("../test_data/1.Yaz0");
let compressed_file = include_bytes!("../test_data/small.txt.Yaz0");

assert_eq!(
compressed_file,
Expand Down
Binary file added test_data/dirt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/dirt.png.Yay0
Binary file not shown.
19 changes: 19 additions & 0 deletions test_data/dirt.png.bin

Large diffs are not rendered by default.

Binary file added test_data/dirt.png.bin.Yay0
Binary file not shown.
Binary file added test_data/ground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/ground.png.Yay0
Binary file not shown.
12 changes: 12 additions & 0 deletions test_data/ground.png.bin

Large diffs are not rendered by default.

Binary file added test_data/ground.png.bin.Yay0
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added test_data/stones.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/stones.png.Yay0
Binary file not shown.
1 change: 1 addition & 0 deletions test_data/stones.png.bin

Large diffs are not rendered by default.

Binary file added test_data/stones.png.bin.Yay0
Binary file not shown.
Binary file added test_data/tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/tile.png.Yay0
Binary file not shown.
1 change: 1 addition & 0 deletions test_data/tile.png.bin

Large diffs are not rendered by default.

Binary file added test_data/tile.png.bin.Yay0
Binary file not shown.

0 comments on commit 0b4360c

Please sign in to comment.