-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No implementation yet, just getting the tests & stub committed.
- Loading branch information
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
[package] | ||
name = "bracket-push" | ||
version = "0.0.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 @@ | ||
|
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,16 @@ | ||
// The code below is a stub. Just enough to satisfy the compiler. | ||
// In order to pass the tests you can add-to or change any of this code. | ||
|
||
pub struct Brackets; | ||
|
||
impl<'a> From<&'a str> for Brackets { | ||
fn from(i: &str) -> Self { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
impl Brackets { | ||
pub fn are_balanced(&self) -> bool { | ||
unimplemented!() | ||
} | ||
} |
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,70 @@ | ||
extern crate bracket_push; | ||
|
||
use bracket_push::*; | ||
|
||
#[test] | ||
fn paired_square_brackets() { | ||
assert!(Brackets::from("[]").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn empty_string() { | ||
assert!(Brackets::from("").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn unpaired_brackets() { | ||
assert!(!Brackets::from("[[").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn wrong_ordered_brackets() { | ||
assert!(!Brackets::from("}{").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn paired_with_whitespace() { | ||
assert!(Brackets::from("{ }").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn simple_nested_brackets() { | ||
assert!(Brackets::from("{[]}").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn several_paired_brackets() { | ||
assert!(Brackets::from("{}[]").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn paired_and_nested_brackets() { | ||
assert!(Brackets::from("([{}({}[])])").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn unopened_closing_brackets() { | ||
assert!(!Brackets::from("{[)][]}").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn unpaired_and_nested_brackets() { | ||
assert!(!Brackets::from("([{])").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn paired_and_wrong_nested_brackets() { | ||
assert!(!Brackets::from("[({]})").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn math_expression() { | ||
assert!(Brackets::from("(((185 + 223.85) * 15) - 543)/2").are_balanced()); | ||
} | ||
|
||
#[test] | ||
fn complex_latex_expression() { | ||
let input = "\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \ | ||
\\end{array}\\right)"; | ||
assert!(Brackets::from(input).are_balanced()); | ||
} |