-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1848 from jqnatividad/100.dathere.com
`tests`: add test_100 for 100.dathere.com & tests for lesson/exercise 0
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// The tests in this file and the test_100 folder are for | ||
// lessons and exercises in the online book "100 exercises with qsv". | ||
|
||
// You may read lessons and try out the exercises at: | ||
// https://100.dathere.com | ||
|
||
// Warning: These tests may contain solutions to the exercises. | ||
|
||
mod exercise_0; |
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,62 @@ | ||
// Lesson 0: Exploring qsv help messages and syntax | ||
// https://100.dathere.com/lessons/0/notes.html | ||
|
||
use std::process; | ||
|
||
use crate::workdir::Workdir; | ||
|
||
fn setup(name: &str, command_str: &str, args: Vec<&str>) -> (Workdir, process::Command) { | ||
let wrk = Workdir::new(name); | ||
wrk.create( | ||
"fruits.csv", | ||
vec![ | ||
svec!["fruit", "price"], | ||
svec!["apple", "2.50"], | ||
svec!["banana", "3.00"], | ||
svec!["carrot", "1.50"], | ||
], | ||
); | ||
|
||
let mut cmd = wrk.command(command_str); | ||
cmd.args(args); | ||
|
||
(wrk, cmd) | ||
} | ||
|
||
// https://100.dathere.com/lessons/0/notes.html#displaying-headers-of-a-csv | ||
#[test] | ||
fn fruits_headers() { | ||
let name = "fruits_headers"; | ||
let command_str = "headers"; | ||
let args = vec!["fruits.csv"]; | ||
let (wrk, mut cmd) = setup(name, command_str, args); | ||
|
||
let got: String = wrk.stdout(&mut cmd); | ||
let expected = r#"1 fruit | ||
2 price"#; | ||
assert_eq!(got, expected); | ||
} | ||
|
||
// https://100.dathere.com/lessons/0/notes.html#exercise-0-total-rows | ||
#[test] | ||
fn fruits_count_total() { | ||
let name = "fruits_count"; | ||
let command_str = "count"; | ||
let args = vec!["fruits.csv", "--no-headers"]; | ||
let (wrk, mut cmd) = setup(name, command_str, args); | ||
|
||
let got: String = wrk.stdout(&mut cmd); | ||
let expected = "4"; | ||
assert_eq!(got, expected); | ||
} | ||
#[test] | ||
fn fruits_count() { | ||
let name = "fruits_count"; | ||
let command_str = "count"; | ||
let args = vec!["fruits.csv"]; | ||
let (wrk, mut cmd) = setup(name, command_str, args); | ||
|
||
let got: String = wrk.stdout(&mut cmd); | ||
let expected = "3"; | ||
assert_eq!(got, expected); | ||
} |
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