-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of forts for each turn (#5)
* Addition of forts for each turn * Addition of forts for each turn * Addition of forts for each turn * Addition of forts for each turn * Addition of forts for each turn * Addition of forts for each turn * Addition of death due to starvation
- Loading branch information
Showing
13 changed files
with
560 additions
and
146 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
FROM rust:1.53 | ||
|
||
RUN apt-get update && apt-get install -y jq | ||
RUN cargo install grcov | ||
RUN rustup component add llvm-tools-preview | ||
RUN rustup toolchain install nightly | ||
FROM quantifex/rust_devtest:1_53 | ||
|
||
CMD ["/bin/bash"] |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use std::str; | ||
use std::io::{Cursor, Read, Seek, SeekFrom}; | ||
use crate::*; | ||
|
||
const ASK_FINISH_MINISTER: &str = "Would you like a minister (y/n)? "; | ||
const ASK_FINISH_FUNERAL: &str = "Would you like a fancy funeral (y/n)? "; | ||
const ASK_FINISH_NOTIFY_KIN: &str = "Would you like to inform your next of kin (y/n)? "; | ||
|
||
const NOTIFY_TELEGRAPH_CHARGE: &str = "That will be $4.50 for the telegraph charge.\n\n"; | ||
const NOTIFY_SADIE_WORRIED: &str = "Your Aunt Sadie in St. Louis is really worried about you...\n\n"; | ||
|
||
pub fn complete_trip<W: Write>(out: &mut W, supplies: &mut Supplies) { | ||
let prefix = include_str!("../strings/complete_prefix.txt"); | ||
let suffix = include_str!("../strings/complete_suffix.txt"); | ||
let supplies_status = format!("Supplies left:\n{}\n", supplies); | ||
out.write(prefix.as_bytes()).unwrap(); | ||
out.write(supplies_status.as_bytes()).unwrap(); | ||
out.write(suffix.as_bytes()).unwrap(); | ||
out.flush().unwrap(); | ||
} | ||
|
||
pub fn handle_death<W: Write, R: BufRead>(out: &mut W, input: &mut R) { | ||
out.write(include_str!("../strings/death_prefix.txt").as_bytes()).unwrap(); | ||
let _ = ask_yn!(ASK_FINISH_MINISTER, out, input); | ||
let _ = ask_yn!(ASK_FINISH_FUNERAL, out, input); | ||
let notify_sadie = ask_yn!(ASK_FINISH_NOTIFY_KIN, out, input); | ||
|
||
if notify_sadie { | ||
out.write(NOTIFY_TELEGRAPH_CHARGE.as_bytes()).unwrap(); | ||
} else { | ||
out.write(NOTIFY_SADIE_WORRIED.as_bytes()).unwrap(); | ||
} | ||
out.write(include_str!("../strings/death_suffix.txt").as_bytes()).unwrap(); | ||
} | ||
|
||
#[test] | ||
fn test_complete_trip() { | ||
let mut supplies = Supplies::new(); | ||
let prefix = include_str!("../strings/complete_prefix.txt"); | ||
let suffix = include_str!("../strings/complete_suffix.txt"); | ||
let trip_message = format!("{}Supplies left:\n{}\n{}", prefix, supplies, suffix); | ||
let mut c = Cursor::new(Vec::new()); | ||
|
||
complete_trip(&mut c, &mut supplies); | ||
c.seek(SeekFrom::Start(0)).unwrap(); | ||
let mut trip_out = Vec::new(); | ||
c.read_to_end(&mut trip_out).unwrap(); | ||
|
||
assert_eq!(trip_message, str::from_utf8(&trip_out).unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_handle_death_notify() { | ||
let prefix = include_str!("../strings/death_prefix.txt"); | ||
let suffix = include_str!("../strings/death_suffix.txt"); | ||
let trip_message = format!("{}{}{}{}{}{}", | ||
prefix, ASK_FINISH_MINISTER, ASK_FINISH_FUNERAL, ASK_FINISH_NOTIFY_KIN, NOTIFY_TELEGRAPH_CHARGE, suffix); | ||
|
||
let mut cout = Cursor::new(Vec::new()); | ||
let mut cin = Cursor::new(Vec::new()); | ||
cin.write(b"y\r\ny\r\ny").unwrap(); | ||
cin.seek(SeekFrom::Start(0)).unwrap(); | ||
// Assert | ||
handle_death(&mut cout, &mut cin); | ||
cout.seek(SeekFrom::Start(0)).unwrap(); | ||
let mut trip_out = Vec::new(); | ||
cout.read_to_end(&mut trip_out).unwrap(); | ||
|
||
assert_eq!(trip_message, str::from_utf8(&trip_out).unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_handle_death_no_notify() { | ||
let prefix = include_str!("../strings/death_prefix.txt"); | ||
let suffix = include_str!("../strings/death_suffix.txt"); | ||
let trip_message = format!("{}{}{}{}{}{}", | ||
prefix, ASK_FINISH_MINISTER, ASK_FINISH_FUNERAL, ASK_FINISH_NOTIFY_KIN, NOTIFY_SADIE_WORRIED, suffix); | ||
|
||
let mut cout = Cursor::new(Vec::new()); | ||
let mut cin = Cursor::new(Vec::new()); | ||
cin.write(b"y\r\ny\r\nn").unwrap(); | ||
cin.seek(SeekFrom::Start(0)).unwrap(); | ||
// Assert | ||
handle_death(&mut cout, &mut cin); | ||
cout.seek(SeekFrom::Start(0)).unwrap(); | ||
let mut trip_out = Vec::new(); | ||
cout.read_to_end(&mut trip_out).unwrap(); | ||
|
||
assert_eq!(trip_message, str::from_utf8(&trip_out).unwrap()); | ||
} |
Oops, something went wrong.