rustup override set "$(cat .rustup)"
cargo run
curl http://localhost:8000/3
Fizz
Last active
September 26, 2017 17:05
-
-
Save clux/e6f2938967a9ab6a1b6c1971f4084369 to your computer and use it in GitHub Desktop.
entrerprise fizzbuzz api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nightly-2017-09-26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
authors = ["Eirik Albrigtsen <[email protected]>"] | |
name = "fizzbuzzapi" | |
version = "0.0.0" | |
[[bin]] | |
doc = false | |
name = "fizzbuzzapi" | |
path = "main.rs" | |
[dependencies] | |
rocket = "0.3.3" | |
rocket_codegen = "0.3.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(plugin)] | |
#![plugin(rocket_codegen)] | |
extern crate rocket; | |
fn fizzbuzz(buzzer: u32) -> String { | |
if buzzer % 15 == 0 { | |
"FizzBuzz".into() | |
} else if buzzer % 3 == 0 { | |
"Fizz".into() | |
} else if buzzer % 5 == 0 { | |
"Buzz".into() | |
} else { | |
buzzer.to_string() | |
} | |
} | |
#[cfg(test)] | |
mod tests { | |
use fizzbuzz; | |
#[test] | |
fn fizz_test() { | |
assert_eq!("Fizz", fizzbuzz(3)); | |
assert_eq!("Buzz", fizzbuzz(5)); | |
assert_eq!("31", fizzbuzz(31)); | |
assert_eq!("FizzBuzz", fizzbuzz(15)); | |
} | |
} | |
#[get("/<buzzer>")] | |
fn buzzmount(buzzer: u32) -> String { | |
fizzbuzz(buzzer) | |
} | |
fn main() { | |
rocket::ignite().mount("/", routes![buzzmount]).launch(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
cargo build | |
cargo test | |
cargo run & | |
sleep 1 | |
res=$(curl http://localhost:8000/3) | |
[[ "$res" == "Fizz" ]] | |
pkill fizzbuzzapi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment