Compare commits
4 Commits
e59b65e034
...
031a487fb5
| Author | SHA1 | Date | |
|---|---|---|---|
| 031a487fb5 | |||
| 8d75a40475 | |||
| 761729900f | |||
| b7bbadfc51 |
259
src/card.rs
259
src/card.rs
@@ -302,6 +302,20 @@ pub const NW_TRIANGLE: [Cell; 9] = [
|
||||
Cell::NW, Cell::Filled, Cell::Filled,
|
||||
];
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub const SW_TRIANGLE: [Cell; 9] = [
|
||||
Cell::SW, Cell::Filled, Cell::Filled,
|
||||
Cell::Empty, Cell::SW, Cell::Filled,
|
||||
Cell::Empty, Cell::Empty, Cell::SW,
|
||||
];
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub const NE_TRIANGLE: [Cell; 9] = [
|
||||
Cell::NE, Cell::Empty, Cell::Empty,
|
||||
Cell::Filled, Cell::NE, Cell::Empty,
|
||||
Cell::Filled, Cell::Filled, Cell::NE
|
||||
];
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub const OCTAGON: [Cell; 9] = [
|
||||
Cell::NW, Cell::Filled, Cell::NE,
|
||||
@@ -461,7 +475,109 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn cut_octagon() {
|
||||
todo!();
|
||||
// Original octagon
|
||||
let octagon = Card {
|
||||
cells: OCTAGON,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// Pairs of each different slice option
|
||||
let vert_left_pair = (
|
||||
Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::NW, Cell::Empty, Cell::Empty,
|
||||
Cell::Filled, Cell::Empty, Cell::Empty,
|
||||
Cell::SW, Cell::Empty, Cell::Empty,
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::Empty, Cell::Filled, Cell::NE,
|
||||
Cell::Empty, Cell::Filled, Cell::Filled,
|
||||
Cell::Empty, Cell::Filled, Cell::SE,
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
let vert_right_pair = (
|
||||
Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::NW, Cell::Filled, Cell::Empty,
|
||||
Cell::Filled, Cell::Filled, Cell::Empty,
|
||||
Cell::SW, Cell::Filled, Cell::Empty,
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::Empty, Cell::Empty, Cell::NE,
|
||||
Cell::Empty, Cell::Empty, Cell::Filled,
|
||||
Cell::Empty, Cell::Empty, Cell::SE,
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
let horiz_top_pair = (
|
||||
Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::NW, Cell::Filled, Cell::NE,
|
||||
Cell::Empty, Cell::Empty, Cell::Empty,
|
||||
Cell::Empty, Cell::Empty, Cell::Empty,
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::Empty, Cell::Empty, Cell::Empty,
|
||||
Cell::Filled, Cell::Filled, Cell::Filled,
|
||||
Cell::SW, Cell::Filled, Cell::SE,
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
let horiz_bottom_pair = (
|
||||
Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::NW, Cell::Filled, Cell::NE,
|
||||
Cell::Filled, Cell::Filled, Cell::Filled,
|
||||
Cell::Empty, Cell::Empty, Cell::Empty,
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::Empty, Cell::Empty, Cell::Empty,
|
||||
Cell::Empty, Cell::Empty, Cell::Empty,
|
||||
Cell::SW, Cell::Filled, Cell::SE,
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
// Run tests
|
||||
let result_vleft = octagon.clone().cut(CutLine::VertLeft);
|
||||
assert_eq!(result_vleft, vert_left_pair);
|
||||
|
||||
let result_vright = octagon.clone().cut(CutLine::VertRight);
|
||||
assert_eq!(result_vright, vert_right_pair);
|
||||
|
||||
let result_hupper = octagon.clone().cut(CutLine::HorizUpper);
|
||||
assert_eq!(result_hupper, horiz_top_pair);
|
||||
|
||||
let result_hlower = octagon.cut(CutLine::HorizLower);
|
||||
assert_eq!(result_hlower, horiz_bottom_pair);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -471,31 +587,160 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn flip_triangle_vertical() {
|
||||
todo!();
|
||||
let tri = Card {
|
||||
cells: NW_TRIANGLE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let expected = Card {
|
||||
cells: SW_TRIANGLE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let result = tri.flip(FlipDir::Vertical);
|
||||
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flip_triangle_horizontal() {
|
||||
todo!();
|
||||
let tri = Card {
|
||||
cells: NW_TRIANGLE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let expected = Card {
|
||||
cells: NE_TRIANGLE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let result = tri.flip(FlipDir::Horizontal);
|
||||
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
|
||||
/// Test transposition on column 1
|
||||
#[test]
|
||||
fn transpose_vertical() {
|
||||
todo!();
|
||||
let left_shape = Card {
|
||||
cells: OCTAGON,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// It's a small NW triangle.
|
||||
let right_shape = Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::Filled, Cell::Empty, Cell::Empty,
|
||||
Cell::SE, Cell::Empty, Cell::NW,
|
||||
Cell::Empty, Cell::NW, Cell::Filled,
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let expected_left = Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::Filled, Cell::Filled, Cell::NE,
|
||||
Cell::SE, Cell::Filled, Cell::Filled,
|
||||
Cell::Empty, Cell::Filled, Cell::SE,
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let expected_right = Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::NW, Cell::Empty, Cell::Empty,
|
||||
Cell::Filled, Cell::Empty, Cell::NW,
|
||||
Cell::SW, Cell::NW, Cell::Filled,
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let (res_left, res_right) = left_shape.transpose(
|
||||
right_shape,
|
||||
TransposeSelection::Column(TransposeIndex::First),
|
||||
);
|
||||
assert_eq!(res_left, expected_left);
|
||||
assert_eq!(res_right, expected_right);
|
||||
}
|
||||
|
||||
/// Test transposition on row 3
|
||||
#[test]
|
||||
fn transpose_horizontal() {
|
||||
todo!();
|
||||
let left_shape = Card {
|
||||
cells: OCTAGON,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let right_shape = Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::Filled, Cell::Empty, Cell::Empty,
|
||||
Cell::SE, Cell::Empty, Cell::NW,
|
||||
Cell::Empty, Cell::NW, Cell::Filled,
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let expected_left = Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::NW, Cell::Filled, Cell::NE,
|
||||
Cell::Filled, Cell::Filled, Cell::Filled,
|
||||
Cell::Empty, Cell::NW, Cell::Filled,
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let expected_right = Card {
|
||||
#[rustfmt::skip]
|
||||
cells: [
|
||||
Cell::Filled, Cell::Empty, Cell::Empty,
|
||||
Cell::SE, Cell::Empty, Cell::NW,
|
||||
Cell::SW, Cell::Filled, Cell::SE,
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let (res_left, res_right) = left_shape.transpose(
|
||||
right_shape,
|
||||
TransposeSelection::Row(TransposeIndex::Third),
|
||||
);
|
||||
assert_eq!(res_left, expected_left);
|
||||
assert_eq!(res_right, expected_right);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rotate_clockwise() {
|
||||
todo!();
|
||||
let shape = Card {
|
||||
cells: NW_TRIANGLE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let expected = Card {
|
||||
cells: NE_TRIANGLE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let result = shape.rotate(RotationDir::Clockwise);
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rotate_counter_clockwise() {
|
||||
todo!();
|
||||
let shape = Card {
|
||||
cells: NE_TRIANGLE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let expected = Card {
|
||||
cells: NW_TRIANGLE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let result = shape.rotate(RotationDir::CounterClockwise);
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user