Skip to content

Commit

Permalink
test: Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Apricot-S committed Sep 24, 2024
1 parent 4a6d7ce commit 3ccb8e5
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/fulu_mianzi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,39 @@ mod tests {
}

#[test]
fn invalid_shunzi() {
fn invalid_shunzi_out_of_range() {
let shunzi_8z_low = FuluMianzi::Shunzi(MAX_TILE_INDEX + 1, ClaimedTilePosition::Low);

assert!(matches!(
shunzi_8z_low.validate().unwrap_err(),
InvalidFuluMianziError::IndexOutOfRange(34)
));
}

#[test]
fn invalid_shunzi_zipai() {
let shunzi_1z_low = FuluMianzi::Shunzi(MAX_SHUPAI_INDEX + 1, ClaimedTilePosition::Low);
let shunzi_7z_high = FuluMianzi::Shunzi(MAX_TILE_INDEX, ClaimedTilePosition::High);

assert!(matches!(
shunzi_1z_low.validate().unwrap_err(),
InvalidFuluMianziError::ShunziWithZipai(27)
));
assert!(matches!(
shunzi_7z_high.validate().unwrap_err(),
InvalidFuluMianziError::ShunziWithZipai(33)
));
}

#[test]
fn invalid_shunzi_combination() {
let shunzi_8m_low = FuluMianzi::Shunzi(7, ClaimedTilePosition::Low);
let shunzi_9m_low = FuluMianzi::Shunzi(8, ClaimedTilePosition::Low);
let shunzi_1m_middle = FuluMianzi::Shunzi(0, ClaimedTilePosition::Middle);
let shunzi_9m_middle = FuluMianzi::Shunzi(8, ClaimedTilePosition::Middle);
let shunzi_1m_high = FuluMianzi::Shunzi(0, ClaimedTilePosition::High);
let shunzi_2m_high = FuluMianzi::Shunzi(1, ClaimedTilePosition::High);

assert!(matches!(
shunzi_1z_low.validate().unwrap_err(),
InvalidFuluMianziError::ShunziWithZipai(27)
));
assert!(matches!(
shunzi_8m_low.validate().unwrap_err(),
InvalidFuluMianziError::InvalidShunziCombination(7, ClaimedTilePosition::Low)
Expand Down

0 comments on commit 3ccb8e5

Please sign in to comment.