Skip to content

Commit cc07829

Browse files
committed
Basic test project, tests intentionally incomplete
1 parent 88f2d1c commit cc07829

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "examplerust"
3+
version = "1.0.0"
4+
authors = ["Sunjay Varma <[email protected]>"]
5+
6+
[dependencies]

src/lib.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const EYES: &'static str = ":";
2+
3+
pub fn smile() -> String {
4+
format!("{}{}", EYES, ")")
5+
}
6+
7+
pub fn frown() -> String {
8+
format!("{}{}", EYES, "(")
9+
}
10+
11+
pub fn angry() -> String {
12+
format!("{}{}{}", ">", EYES, "(")
13+
}
14+
15+
/// Provides a string representation of a face
16+
///
17+
/// # Examples
18+
///
19+
/// ```
20+
/// # use examplerust::*;
21+
/// assert_eq!(which(&frown()), "Frown");
22+
/// ```
23+
pub fn which(face: &str) -> &'static str {
24+
if face == smile() {
25+
"Smile"
26+
}
27+
else if face == frown() {
28+
"Frown"
29+
}
30+
else if face == angry() {
31+
"Angry"
32+
}
33+
else {
34+
"I don't know"
35+
}
36+
}
37+
38+
#[cfg(test)]
39+
mod tests {
40+
use super::*;
41+
42+
#[test]
43+
fn can_smile() {
44+
assert_eq!(smile(), ":)");
45+
}
46+
47+
#[test]
48+
fn can_frown() {
49+
assert_eq!(frown(), ":(");
50+
}
51+
52+
#[test]
53+
fn can_angry() {
54+
assert_eq!(angry(), ">:(");
55+
}
56+
57+
#[test]
58+
fn string_representation() {
59+
assert_eq!(which(&smile()), "Smile");
60+
}
61+
}
62+

0 commit comments

Comments
 (0)