add unit tests for into command
This commit is contained in:
parent
1cf37413e6
commit
b3bf57301a
6 changed files with 113 additions and 16 deletions
|
|
@ -173,9 +173,9 @@ impl BitmapCommand {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::command_code::CommandCode;
|
||||
use crate::commands::tests::TestImplementsCommand;
|
||||
use crate::*;
|
||||
use crate::{
|
||||
command_code::CommandCode, commands::tests::TestImplementsCommand,
|
||||
};
|
||||
|
||||
impl TestImplementsCommand for BitmapCommand {}
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ mod tests {
|
|||
#[test]
|
||||
fn error_decompression_failed_win() {
|
||||
for compression in CompressionCode::ALL {
|
||||
let p: Packet = commands::BitmapCommand {
|
||||
let p: Packet = BitmapCommand {
|
||||
origin: Origin::new(16, 8),
|
||||
bitmap: Bitmap::new(8, 8).unwrap(),
|
||||
compression: *compression,
|
||||
|
|
@ -226,4 +226,19 @@ mod tests {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_command() {
|
||||
let mut bitmap = Bitmap::max_sized();
|
||||
bitmap.fill(true);
|
||||
|
||||
assert_eq!(
|
||||
BitmapCommand::from(bitmap.clone()),
|
||||
BitmapCommand {
|
||||
bitmap,
|
||||
origin: Origin::default(),
|
||||
compression: CompressionCode::default()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,9 +141,12 @@ impl From<BitVec> for BitVecCommand {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::commands::tests::{round_trip, TestImplementsCommand};
|
||||
use crate::compression_code::InvalidCompressionCodeError;
|
||||
use crate::{commands, Bitmap, BitmapCommand, Origin};
|
||||
use crate::{
|
||||
commands,
|
||||
commands::tests::{round_trip, TestImplementsCommand},
|
||||
compression_code::InvalidCompressionCodeError,
|
||||
Bitmap, BitmapCommand, Origin, PIXEL_WIDTH,
|
||||
};
|
||||
|
||||
impl TestImplementsCommand for BitVecCommand {}
|
||||
|
||||
|
|
@ -327,4 +330,20 @@ mod tests {
|
|||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_command() {
|
||||
let mut bitvec = BitVec::repeat(true, PIXEL_WIDTH);
|
||||
bitvec.fill(true);
|
||||
|
||||
assert_eq!(
|
||||
BitVecCommand::from(bitvec.clone()),
|
||||
BitVecCommand {
|
||||
bitvec,
|
||||
offset: 0,
|
||||
compression: CompressionCode::default(),
|
||||
operation: BinaryOperation::Overwrite,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,11 +85,12 @@ impl From<Brightness> for BrightnessCommand {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::command_code::CommandCode;
|
||||
use crate::commands::errors::TryFromPacketError;
|
||||
use crate::commands::tests::{round_trip, TestImplementsCommand};
|
||||
use crate::{
|
||||
commands, Brightness, BrightnessCommand, Header, Packet, TypedCommand,
|
||||
command_code::CommandCode,
|
||||
commands,
|
||||
commands::errors::TryFromPacketError,
|
||||
commands::tests::{round_trip, TestImplementsCommand},
|
||||
Brightness, BrightnessCommand, Header, Packet, TypedCommand,
|
||||
};
|
||||
|
||||
impl TestImplementsCommand for BrightnessCommand {}
|
||||
|
|
@ -177,4 +178,14 @@ mod tests {
|
|||
Err(TryFromPacketError::InvalidBrightness(42))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_command() {
|
||||
assert_eq!(
|
||||
BrightnessCommand::from(Brightness::MIN),
|
||||
BrightnessCommand {
|
||||
brightness: Brightness::MIN,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,10 +85,11 @@ impl From<BrightnessGridCommand> for TypedCommand {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::commands::errors::TryFromPacketError;
|
||||
use crate::commands::tests::{round_trip, TestImplementsCommand};
|
||||
use crate::{
|
||||
commands, BrightnessGrid, BrightnessGridCommand, Origin, Packet,
|
||||
commands,
|
||||
commands::errors::TryFromPacketError,
|
||||
commands::tests::{round_trip, TestImplementsCommand},
|
||||
Brightness, BrightnessGrid, BrightnessGridCommand, Origin, Packet,
|
||||
TypedCommand,
|
||||
};
|
||||
|
||||
|
|
@ -120,4 +121,20 @@ mod tests {
|
|||
Err(TryFromPacketError::InvalidBrightness(23))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_command() {
|
||||
let mut grid = BrightnessGrid::new(2, 3);
|
||||
grid.iter_mut().enumerate().for_each(|(index, value)| {
|
||||
*value = Brightness::saturating_from(index as u8)
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
BrightnessGridCommand::from(grid.clone()),
|
||||
BrightnessGridCommand {
|
||||
grid,
|
||||
origin: Origin::default(),
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,8 +93,11 @@ impl From<CharGrid> for CharGridCommand {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::commands::tests::{round_trip, TestImplementsCommand};
|
||||
use crate::{CharGrid, CharGridCommand, Origin};
|
||||
use crate::{
|
||||
commands::tests::{round_trip, TestImplementsCommand},
|
||||
cp437::cp437_to_char,
|
||||
CharGrid, CharGridCommand, Origin,
|
||||
};
|
||||
|
||||
impl TestImplementsCommand for CharGridCommand {}
|
||||
|
||||
|
|
@ -108,4 +111,20 @@ mod tests {
|
|||
.into(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_command() {
|
||||
let mut grid = CharGrid::new(2, 3);
|
||||
grid.iter_mut()
|
||||
.enumerate()
|
||||
.for_each(|(index, value)| *value = cp437_to_char(index as u8));
|
||||
|
||||
assert_eq!(
|
||||
CharGridCommand::from(grid.clone()),
|
||||
CharGridCommand {
|
||||
grid,
|
||||
origin: Origin::default(),
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,4 +116,20 @@ mod tests {
|
|||
.into(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_command() {
|
||||
let mut grid = Cp437Grid::new(2, 3);
|
||||
grid.iter_mut()
|
||||
.enumerate()
|
||||
.for_each(|(index, value)| *value = index as u8);
|
||||
|
||||
assert_eq!(
|
||||
Cp437GridCommand::from(grid.clone()),
|
||||
Cp437GridCommand {
|
||||
grid,
|
||||
origin: Origin::default(),
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue