Skip to content

Commit

Permalink
add extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m4salah committed Dec 9, 2023
1 parent 1728bc4 commit 4a59412
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/handlers/day6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,64 @@ mod tests {
use axum::http::StatusCode;
use axum_test_helper::TestClient;

#[tokio::test]
async fn test_empty_shelves() {
let app = router();

let client = TestClient::new(app);
let res = client
.post("/6")
.body("")
.header("Content-Type", "text/plain")
.send()
.await;
assert_eq!(res.status(), StatusCode::OK);
let expected = ElfOnShelfResult {
..Default::default()
};
assert_eq!(res.json::<ElfOnShelfResult>().await, expected);
}

#[tokio::test]
async fn test_no_elf_on_shelves() {
let app = router();

let client = TestClient::new(app);
let res = client
.post("/6")
.body("there is a shelf. another shelf here.")
.header("Content-Type", "text/plain")
.send()
.await;
assert_eq!(res.status(), StatusCode::OK);
let expected = ElfOnShelfResult {
elf: 2,
shelf_with_no_elf_on_it: 2,
..Default::default()
};
assert_eq!(res.json::<ElfOnShelfResult>().await, expected);
}

#[tokio::test]
async fn test_mixed_shelves() {
let app = router();

let client = TestClient::new(app);
let res = client
.post("/6")
.body("there is an elf on a shelf. another shelf here. elf on a shelf.")
.header("Content-Type", "text/plain")
.send()
.await;
assert_eq!(res.status(), StatusCode::OK);
let expected = ElfOnShelfResult {
elf: 5,
elf_on_a_shelf: 2,
shelf_with_no_elf_on_it: 1,
};
assert_eq!(res.json::<ElfOnShelfResult>().await, expected);
}

#[tokio::test]
async fn elf() {
let app = router();
Expand Down

0 comments on commit 4a59412

Please sign in to comment.