Skip to content

Commit

Permalink
Add better tests and document integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aneshodza committed Apr 24, 2024
1 parent 73c44a3 commit 295a733
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ It only checks for these two things on the node it's currently on (while being i
---

## Usage
**Important:** This just goes over creating an automaton using every configuration option. [Here](./tests/integration_tests/README.md) you can find real use-cases.
Creating a pushdown automaton involves following steps:
1. Creating the automaton instance
2. Creating all the states
Expand Down Expand Up @@ -103,4 +104,4 @@ It holds a message, if it was sucessful and the return code. Following codes are
- [Feature requests](./docs/FEATURE_REQUESTS.md)

#### Credits
This library was written and published by [Anes Hodza](aneshodza.ch)
This library was written and published by [Anes Hodza](https://aneshodza.ch)
23 changes: 23 additions & 0 deletions tests/integration_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Real use-cases
In this folder you can find tests of real applications of pushdown automata.

## Balanced parantheses
This pushdown automaton can check if the input word has balanced parantheses. This is how the language is defined:
$$`
L = \{ w \mid w \text{ is a string of balanced parentheses} \}
`$$
**Accepted words that are tested:**
```
-> (()())
-> ()()()
-> ((()))
-> ()(()())
```

**Not accepted words that are tested:**
```
-> (()()
-> ())
-> ((())
-> )()()
```
22 changes: 17 additions & 5 deletions tests/integration_tests/balances_parantheses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,28 @@ beforeEach(() => {

test("Balanced parentheses", () => {
let result = automaton.run("(()())");

expect(result.successful).toBe(true);

let result2 = automaton.run("()()()");
expect(result2.successful).toBe(true);

let result3 = automaton.run("((()))");
expect(result3.successful).toBe(true);

let result4 = automaton.run("()(()())");
expect(result4.successful).toBe(true);
});

test("Unbalanced parentheses", () => {
let result = automaton.run("(()()");
expect(result.successful).toBe(false);
});

test("When starting with a bad character", () => {
let result = automaton.run(")()()");
expect(result.successful).toBe(false);
let result2 = automaton.run("())");
expect(result2.successful).toBe(false);

let result3 = automaton.run("((())");
expect(result3.successful).toBe(false);

let result4 = automaton.run(")()()");
expect(result4.successful).toBe(false);
});

0 comments on commit 295a733

Please sign in to comment.