Skip to content

Commit

Permalink
WIP: Implement Bracket Push
Browse files Browse the repository at this point in the history
No implementation yet, just getting the tests & stub committed.
  • Loading branch information
whit0694 committed Aug 23, 2016
1 parent 4b8ab31 commit babb763
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exercises/bracket-push/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions exercises/bracket-push/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "bracket-push"
version = "0.0.0"
1 change: 1 addition & 0 deletions exercises/bracket-push/example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

16 changes: 16 additions & 0 deletions exercises/bracket-push/src/lib.rs
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!()
}
}
70 changes: 70 additions & 0 deletions exercises/bracket-push/tests/bracket-push.rs
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());
}

0 comments on commit babb763

Please sign in to comment.