Commit cec9fed7 authored by Stefan Schindler's avatar Stefan Schindler
Browse files

Implement - for ByteUnit

parent 3eec1dbc
......@@ -206,17 +206,19 @@ impl std::ops::AddAssign for ByteUnit {
}
}
}
impl std::ops::Sub for ByteUnit {
type Output = ByteUnit;
#[derive(Debug,PartialEq,Eq)]
enum DiskState {
Detected,
QueueForWhipe,
Whiping{ progress: ByteUnit, per_second: ByteUnit },
Whiped,
WhipeFailed,
fn sub(self, other: Self) -> Self {
match self {
Byte(l) => match other {
Byte(r) => Byte(l - r),
something_else => self - something_else.to_byte(),
},
something_else => something_else.to_byte() - other,
}
}
}
use DiskState::*;
impl Display for ByteUnit {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
......@@ -449,4 +451,22 @@ mod test {
four += Byte(2);
assert_eq!(Byte(2 + 2048), four);
}
#[test]
fn sub_bytes() {
assert_eq!(Byte(0), Byte(2) - Byte(2));
}
#[test]
fn sub_kilobytes() {
assert_eq!(KiloByte(0), KiloByte(2) - KiloByte(2));
}
#[test]
fn sub_bytes_mixed_up() {
assert_eq!(Byte(2), Byte(2048 + 2) - KiloByte(2));
}
#[test]
fn sub_bytes_mixed_down() {
assert_eq!(Byte(2048 - 2), KiloByte(2) - Byte(2));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment