Skip to content

Instantly share code, notes, and snippets.

@clux
Last active September 26, 2017 17:05
Show Gist options
  • Save clux/e6f2938967a9ab6a1b6c1971f4084369 to your computer and use it in GitHub Desktop.
Save clux/e6f2938967a9ab6a1b6c1971f4084369 to your computer and use it in GitHub Desktop.
entrerprise fizzbuzz api
nightly-2017-09-26

fizzbuzz api

rustup override set "$(cat .rustup)"
cargo run
curl http://localhost:8000/3
Fizz
[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"
#![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();
}
#!/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