From 4a59412c0e9a6b73fb232df0a28756864b621642 Mon Sep 17 00:00:00 2001 From: "Mohamed A. Salah" Date: Sat, 9 Dec 2023 22:40:41 +0200 Subject: [PATCH] add extra tests --- src/handlers/day6.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/handlers/day6.rs b/src/handlers/day6.rs index a23b0f4..1898f65 100644 --- a/src/handlers/day6.rs +++ b/src/handlers/day6.rs @@ -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::().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::().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::().await, expected); + } + #[tokio::test] async fn elf() { let app = router();