add tests

This commit is contained in:
Vinzenz Schroeter 2025-03-08 17:37:13 +01:00
parent 7cd26cd50e
commit b178b48834
4 changed files with 40 additions and 9 deletions

View file

@ -160,10 +160,8 @@ impl BitmapCommand {
#[cfg(test)]
mod tests {
use crate::command_code::CommandCode;
use crate::{
commands, Bitmap, BitmapCommand, CompressionCode, Header, Origin,
Packet, TryFromPacketError, TypedCommand,
};
use crate::*;
use super::*;
#[test]
fn command_code() {

View file

@ -108,8 +108,6 @@ fn check_command_code_only(
#[cfg(test)]
mod tests {
use crate::command_code::CommandCode;
use crate::commands::{BinaryOperation, TryFromPacketError};
use crate::*;
pub(crate) fn round_trip(original: TypedCommand) {

View file

@ -278,7 +278,7 @@ impl<'t> Iterator for IterRows<'t> {
}
}
#[derive(thiserror::Error, Debug)]
#[derive(thiserror::Error, Debug, PartialEq)]
pub enum LoadBitmapError {
#[error("The provided width is not divisible by 8.")]
InvalidWidth,
@ -290,7 +290,7 @@ pub enum LoadBitmapError {
#[cfg(test)]
mod tests {
use crate::{BitVec, Bitmap, DataRef, Grid, ValueGrid};
use crate::{BitVec, Bitmap, DataRef, Grid, LoadBitmapError, ValueGrid};
#[test]
fn fill() {
@ -402,4 +402,39 @@ mod tests {
let reconverted = ValueGrid::from(&converted);
assert_eq!(original, reconverted);
}
#[test]
fn load_invalid_width() {
let data = BitVec::repeat(false, 7*3).into_vec();
assert_eq!(Bitmap::load(7, 3, &data), Err(LoadBitmapError::InvalidWidth))
}
#[test]
fn load_invalid_size() {
let data = BitVec::repeat(false, 8*4).into_vec();
assert_eq!(Bitmap::load(8, 3, &data), Err(LoadBitmapError::InvalidDataSize))
}
#[test]
fn from_vec_invalid_width() {
let data = BitVec::repeat(false, 7*3);
assert_eq!(Bitmap::from_bitvec(7, data), Err(LoadBitmapError::InvalidWidth))
}
#[test]
fn from_vec_invalid_size() {
let data = BitVec::repeat(false, 7*4);
assert_eq!(Bitmap::from_bitvec(8, data), Err(LoadBitmapError::InvalidDataSize))
}
#[test]
fn from_vec() {
let orig = Bitmap::new(8, 3).unwrap();
assert_eq!(Bitmap::from_bitvec(8, orig.bit_vec.clone()).unwrap(), orig);
}
#[test]
fn new_invalid_width() {
assert_eq!(Bitmap::new(7,2), None)
}
}

View file

@ -9,7 +9,7 @@ mod grid;
mod value_grid;
pub use bit_vec::{bitvec, BitVec};
pub use bitmap::Bitmap;
pub use bitmap::*;
pub use brightness_grid::BrightnessGrid;
pub use byte_grid::ByteGrid;
pub use char_grid::CharGrid;