Skip to content

Commit

Permalink
Add custom assert_eq
Browse files Browse the repository at this point in the history
  • Loading branch information
mlafeldt committed Dec 23, 2021
1 parent 43f6ac4 commit 762b11c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
16 changes: 6 additions & 10 deletions src/cb1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ const SEEDS: [[u32; 16]; 3] = [
#[cfg(test)]
mod tests {
use super::*;
use crate::code::Code;
use crate::std_alloc::{vec, ToString, Vec};
#[cfg(feature = "std")]
use pretty_assertions::assert_eq;
use crate::code::{assert_eq, Code};
use crate::std_alloc::{vec, Vec};

struct Test {
decrypted: &'static str,
Expand Down Expand Up @@ -140,8 +138,7 @@ mod tests {
fn test_encrypt_code() {
for t in tests().iter() {
let code = Code::from(t.decrypted);
let result = encrypt_code(code.0, code.1);
assert_eq!(Code::from(result).to_string(), t.encrypted);
assert_eq(encrypt_code(code.0, code.1), t.encrypted);
}
}

Expand All @@ -150,16 +147,15 @@ mod tests {
for t in tests().iter() {
let mut code = Code::from(t.decrypted);
encrypt_code_mut(&mut code.0, &mut code.1);
assert_eq!(code.to_string(), t.encrypted);
assert_eq(code, t.encrypted);
}
}

#[test]
fn test_decrypt_code() {
for t in tests().iter() {
let code = Code::from(t.encrypted);
let result = decrypt_code(code.0, code.1);
assert_eq!(Code::from(result).to_string(), t.decrypted);
assert_eq(decrypt_code(code.0, code.1), t.decrypted);
}
}

Expand All @@ -168,7 +164,7 @@ mod tests {
for t in tests().iter() {
let mut code = Code::from(t.encrypted);
decrypt_code_mut(&mut code.0, &mut code.1);
assert_eq!(code.to_string(), t.decrypted);
assert_eq(code, t.decrypted);
}
}
}
12 changes: 6 additions & 6 deletions src/cb7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ const SEEDS: [[u8; 256]; 5] = [
#[cfg(test)]
mod tests {
use super::*;
use crate::code::Code;
use crate::std_alloc::{vec, ToString, Vec};
use crate::code::{assert_eq, Code};
use crate::std_alloc::{vec, Vec};
#[cfg(feature = "std")]
use pretty_assertions::assert_eq;

Expand Down Expand Up @@ -597,7 +597,7 @@ mod tests {
for (i, &line) in t.decrypted.iter().enumerate() {
let code = Code::from(line);
let result = cb7.encrypt_code(code.0, code.1);
assert_eq!(Code::from(result).to_string(), t.encrypted[i]);
assert_eq(result, t.encrypted[i]);

if is_beefcode(code.0) {
cb7.beefcode(code.0, code.1)
Expand All @@ -617,7 +617,7 @@ mod tests {
let mut code = Code::from(line);
let oldcode = code;
cb7.encrypt_code_mut(&mut code.0, &mut code.1);
assert_eq!(code.to_string(), t.encrypted[i]);
assert_eq(code, t.encrypted[i]);

if is_beefcode(oldcode.0) {
cb7.beefcode(oldcode.0, oldcode.1)
Expand All @@ -636,7 +636,7 @@ mod tests {
for (i, &line) in t.encrypted.iter().enumerate() {
let code = Code::from(line);
let result = cb7.decrypt_code(code.0, code.1);
assert_eq!(Code::from(result).to_string(), t.decrypted[i]);
assert_eq(result, t.decrypted[i]);

if is_beefcode(result.0) {
cb7.beefcode(result.0, result.1)
Expand All @@ -655,7 +655,7 @@ mod tests {
for (i, &line) in t.encrypted.iter().enumerate() {
let mut code = Code::from(line);
cb7.decrypt_code_mut(&mut code.0, &mut code.1);
assert_eq!(code.to_string(), t.decrypted[i]);
assert_eq(code, t.decrypted[i]);

if is_beefcode(code.0) {
cb7.beefcode(code.0, code.1)
Expand Down
26 changes: 15 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,8 @@ const fn num_code_lines(addr: u32) -> usize {
#[cfg(test)]
mod tests {
use super::*;
use crate::code::Code;
use crate::std_alloc::{vec, ToString, Vec};
#[cfg(feature = "std")]
use pretty_assertions::assert_eq;
use crate::code::{assert_eq, Code};
use crate::std_alloc::{vec, Vec};

struct Test {
cb: Codebreaker,
Expand Down Expand Up @@ -377,7 +375,7 @@ mod tests {
for (i, &line) in t.decrypted.iter().enumerate() {
let code = Code::from(line);
let result = t.cb.encrypt_code(code.0, code.1);
assert_eq!(Code::from(result).to_string(), t.encrypted[i]);
assert_eq(result, t.encrypted[i]);
}
}
}
Expand All @@ -388,7 +386,7 @@ mod tests {
for (i, &line) in t.decrypted.iter().enumerate() {
let mut code = Code::from(line);
t.cb.encrypt_code_mut(&mut code.0, &mut code.1);
assert_eq!(code.to_string(), t.encrypted[i]);
assert_eq(code, t.encrypted[i]);
}
}
}
Expand All @@ -399,7 +397,7 @@ mod tests {
for (i, &line) in t.encrypted.iter().enumerate() {
let code = Code::from(line);
let result = t.cb.decrypt_code(code.0, code.1);
assert_eq!(Code::from(result).to_string(), t.decrypted[i]);
assert_eq(result, t.decrypted[i]);
}
}
}
Expand All @@ -410,7 +408,7 @@ mod tests {
for (i, &line) in t.encrypted.iter().enumerate() {
let mut code = Code::from(line);
t.cb.decrypt_code_mut(&mut code.0, &mut code.1);
assert_eq!(code.to_string(), t.decrypted[i]);
assert_eq(code, t.decrypted[i]);
}
}
}
Expand Down Expand Up @@ -504,7 +502,7 @@ mod tests {
for (i, &line) in t.input.iter().enumerate() {
let code = Code::from(line);
let result = cb.auto_decrypt_code(code.0, code.1);
assert_eq!(Code::from(result).to_string(), t.output[i]);
assert_eq(result, t.output[i]);
}
}
}
Expand All @@ -516,15 +514,15 @@ mod tests {
for (i, &line) in t.input.iter().enumerate() {
let mut code = Code::from(line);
cb.auto_decrypt_code_mut(&mut code.0, &mut code.1);
assert_eq!(code.to_string(), t.output[i]);
assert_eq(code, t.output[i]);
}
}
}
}

#[cfg(test)]
mod code {
use crate::std_alloc::{fmt, Vec};
use crate::std_alloc::{fmt, ToString, Vec};

#[derive(Debug, Copy, Clone)]
pub struct Code(pub u32, pub u32);
Expand All @@ -551,4 +549,10 @@ mod code {
write!(f, "{:08X} {:08X}", self.0, self.1)
}
}

pub fn assert_eq(a: impl Into<Code>, b: impl Into<Code>) {
#[cfg(feature = "std")]
use pretty_assertions::assert_eq;
assert_eq!(a.into().to_string(), b.into().to_string());
}
}

0 comments on commit 762b11c

Please sign in to comment.