Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit b12dc64

Browse files
committedOct 22, 2020
Fixing CI
1 parent 0aadec0 commit b12dc64

File tree

14 files changed

+79
-65
lines changed

14 files changed

+79
-65
lines changed
 

‎.github/workflows/main.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches:
6+
- master
67
pull_request:
7-
branches: [ master ]
8+
branches:
9+
- master
810

911
jobs:
1012
jest-tests:
@@ -14,10 +16,8 @@ jobs:
1416
- name: Install modules
1517
run: yarn
1618
- name: Run tests
17-
run: yarn jest --json --outputFile="jest.results.json"
18-
- uses: mattallty/jest-github-action@v1.0.3
19-
if: github.event_name == 'pull_request'
20-
env:
21-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
run: yarn jest --json --outputFile=jest.results.json
20+
- name: Upload coverage to Codecov
21+
uses: codecov/codecov-action@v1
2222
with:
23-
changes-only: true
23+
token: ${{ secrets.CODECOV_TOKEN }}

‎.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# IntelliJ project files
22
.idea
33
*.iml
4-
package-lock.json
5-
yarn.lock
4+
yarn.lock
5+
coverage

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# PDA-CFG Question Generator
22
![CI](https://github.com/hollandjake/pda-cfg-generator/workflows/CI/badge.svg)
3-
3+
[![codecov](https://codecov.io/gh/hollandjake/pda-cfg-generator/branch/master/graph/badge.svg?token=FS9WF9ZYTT)](https://codecov.io/gh/hollandjake/pda-cfg-generator)

‎jest.config.js

-3
This file was deleted.

‎package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"babel-jest": "^26.6.0",
66
"jest": "^26.6.0"
77
},
8-
"dependencies": {
9-
"@jest/globals": "^26.6.0"
8+
"scripts": {
9+
"test": "jest"
10+
},
11+
"jest": {
12+
"collectCoverage": true
1013
}
1114
}

‎src/internal/cfg/CFG.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Symbol from "../Symbol.js";
22
import ArrayHelper from "../helper/ArrayHelper.js";
33
import Variable from "./Variable.js";
44
import Terminal from "./Terminal.js";
5-
import CFGSymbol from "./CFGSymbol.js";
65
import Rule from "./Rule.js";
76

87
export default class CFG {
@@ -55,6 +54,8 @@ export default class CFG {
5554
variables.push(symbol);
5655
} else if (symbol instanceof Terminal) {
5756
terminals.push(symbol);
57+
} else {
58+
throw new Error("One of the Rule's outputList elements isn't supported, please use 'Terminal' or 'Variable'");
5859
}
5960
})
6061
})
@@ -63,7 +64,7 @@ export default class CFG {
6364
throw new Error("Start variable not found in variables");
6465
}
6566

66-
return new CFG(variables, terminals, rules, startVariable)
67+
return new CFG(variables, terminals, rules, startVariable);
6768
}
6869

6970
/**
@@ -79,7 +80,7 @@ export default class CFG {
7980
if (inputString !== null && inputString.length > 0) {
8081
let ruleStrings = inputString.split(/[,\n]/);
8182

82-
let rules = ruleStrings.map(rule => Rule.fromString(rule))
83+
let rules = ruleStrings.map(rule => Rule.fromString(rule)).filter(rule => rule !== null);
8384

8485
if (rules.length > 0) {
8586
let startVariable = rules[0].inputVariable;

‎src/internal/cfg/Rule.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export default class Rule {
2020
this._outputList = outputList;
2121
}
2222

23+
get inputVariable() {
24+
return this._inputVariable;
25+
}
26+
27+
get outputList() {
28+
return this._outputList;
29+
}
30+
2331
/**
2432
* Parse a {Rule} from a string using the format <Variable> -> <Variable|Terminal>*
2533
* @param {String} ruleString
@@ -44,17 +52,8 @@ export default class Rule {
4452
return null;
4553
}
4654

47-
48-
get inputVariable() {
49-
return this._inputVariable;
50-
}
51-
52-
get outputList() {
53-
return this._outputList;
54-
}
55-
5655
/* istanbul ignore next */
5756
toString() {
58-
return `${this._inputVariable}${this.outputList.map(s => s.id).join('')}`
57+
return `${this._inputVariable}${this.outputList.map(s => s.id).join('')}`;
5958
}
6059
}

‎src/internal/pda/PDA.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class PDA {
7777
throw new Error("Start start not found in transition states");
7878
}
7979

80-
return new PDA(states, inputAlphabet, stackAlphabet, transitions, startState, acceptStates)
80+
return new PDA(states, inputAlphabet, stackAlphabet, transitions, startState, acceptStates);
8181
}
8282

8383
/* istanbul ignore next */

‎test/internal/Symbol.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ test('Sorting symbols correctly', () => {
44
let input = [Symbol.of("B"), Symbol.of("A")];
55
let target = [Symbol.of("A"), Symbol.of("B")];
66
expect(Symbol.sort(input)).toEqual(target);
7-
})
7+
});
88

99
test('Sorting symbols correctly with duplicates', () => {
1010
let input = [Symbol.of("B"), Symbol.of("A"), Symbol.of("A")];
11-
let target = [Symbol.of("A"), Symbol.of("A"),Symbol.of("B")];
11+
let target = [Symbol.of("A"), Symbol.of("A"), Symbol.of("B")];
1212
expect(Symbol.sort(input)).toEqual(target);
1313
})

‎test/internal/cfg/CFG.test.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Rule from "../../../src/internal/cfg/Rule.js";
22
import CFG from "../../../src/internal/cfg/CFG.js";
33
import CFGSymbol from "../../../src/internal/cfg/CFGSymbol.js";
44
import Variable from "../../../src/internal/cfg/Variable.js";
5+
import Symbol from "../../../src/internal/Symbol.js";
56

67
test('Creates a CFG', () => {
78
let startVariable = Variable.S;
@@ -16,14 +17,14 @@ test('Creates a CFG', () => {
1617
})
1718

1819
test('Throws Error When Constructing CFG with NULL startVariable', () => {
19-
expect(() => {
20-
new CFG([], [], [], null);
21-
}).toThrowError();
20+
expect(() => {
21+
new CFG([], [], [], null);
22+
}).toThrowError();
2223
});
2324

2425
test('Throws Error When Constructing CFG with non Variable startVariable', () => {
2526
expect(() => {
26-
new CFG([], [], [], {id:1});
27+
new CFG([], [], [], {id: 1});
2728
}).toThrowError();
2829
});
2930

@@ -41,11 +42,20 @@ test('Creates a CFG from rules', () => {
4142
})
4243

4344
test('Throws Error When Creating a CFG from rules and startVariable isnt in rules', () => {
44-
expect(()=> {
45+
expect(() => {
4546
CFG.fromRules([], Variable.S)
4647
}).toThrowError();
4748
})
4849

50+
51+
test('Throws Error When Creating a CFG from rules and outputList contains a non Terminal or Variable', () => {
52+
expect(() => {
53+
CFG.fromRules([
54+
new Rule(Variable.S,[Symbol.of("a")])
55+
])
56+
}).toThrowError();
57+
})
58+
4959
test('Can parse string input', () => {
5060
let cfg = CFG.fromString("A->aA,B->bB");
5161
let target = CFG.fromRules([
@@ -55,10 +65,14 @@ test('Can parse string input', () => {
5565
expect(cfg).toEqual(target);
5666
})
5767

58-
test('Returns null when no rules given to string parser', () => {
68+
test('Returns null when empty input given to string parser', () => {
5969
expect(CFG.fromString("")).toBe(null);
6070
})
6171

72+
test('Returns null when no rules given to string parser', () => {
73+
expect(CFG.fromString(",")).toBe(null);
74+
})
75+
6276
test('Returns null when null given to string parser', () => {
6377
expect(CFG.fromString(null)).toBe(null);
6478
})

‎test/internal/cfg/Rule.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Rule from "../../../src/internal/cfg/Rule.js";
22
import Variable from "../../../src/internal/cfg/Variable.js";
33
import CFGSymbol from "../../../src/internal/cfg/CFGSymbol.js";
4-
import CFG from "../../../src/internal/cfg/CFG.js";
54

65
test('Construct new Rule', () => {
76
let S = CFGSymbol.of("S");
@@ -19,7 +18,7 @@ test('Expect error when creating a Rule with null inputVariable', () => {
1918

2019
test('Expect error when creating a Rule with non Variable inputVariable', () => {
2120
expect(() => {
22-
new Rule({id:1}, []);
21+
new Rule({id: 1}, []);
2322
}).toThrowError();
2423
});
2524

@@ -44,7 +43,7 @@ test('Expect error when creating a Rule with empty outputList', () => {
4443
test('Can parse string input', () => {
4544
let rule = Rule.fromString("A->aA");
4645
expect(rule.inputVariable).toEqual(CFGSymbol.of("A"));
47-
expect(rule.outputList).toEqual([CFGSymbol.of("a"),CFGSymbol.of("A")]);
46+
expect(rule.outputList).toEqual([CFGSymbol.of("a"), CFGSymbol.of("A")]);
4847
})
4948

5049
test('Returns null when empty string given to string parser', () => {
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import ObjectHelper from "../../../src/internal/helper/ObjectHelper.js";
22

33
test('equals [NULL,NULL]', () => {
4-
expect(ObjectHelper.equals(null,null)).toBe(true);
4+
expect(ObjectHelper.equals(null, null)).toBe(true);
55
})
66
test('equals [NULL,primative]', () => {
7-
expect(ObjectHelper.equals(null,'')).toBe(null == '');
7+
expect(ObjectHelper.equals(null, '')).toBe(null == '');
88
})
99
test('equals [primative,NULL]', () => {
10-
expect(ObjectHelper.equals('',null)).toBe('' == null);
10+
expect(ObjectHelper.equals('', null)).toBe('' == null);
1111
})
1212
test('equals [{id:1},{id:1}]', () => {
13-
expect(ObjectHelper.equals({id:1}, {id:1})).toBe(true);
13+
expect(ObjectHelper.equals({id: 1}, {id: 1})).toBe(true);
1414
})
1515

1616
test('equals != [{id:1},{id:2}]', () => {
17-
expect(ObjectHelper.equals({id:1}, {id:2})).toBe(false);
17+
expect(ObjectHelper.equals({id: 1}, {id: 2})).toBe(false);
1818
})
1919

2020
test('equals [{id:1}, {id:1,name:\'test\'}]', () => {
21-
expect(ObjectHelper.equals({id:1}, {id:1, name: 'test'})).toBe(false);
21+
expect(ObjectHelper.equals({id: 1}, {id: 1, name: 'test'})).toBe(false);
2222
})
2323

2424
test('equals [{id:1,name:\'test\'}, {id:1}]', () => {
25-
expect(ObjectHelper.equals({id:1, name: 'test'}, {id:1})).toBe(false);
25+
expect(ObjectHelper.equals({id: 1, name: 'test'}, {id: 1})).toBe(false);
2626
})

‎test/internal/pda/PDA.test.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,36 @@ test('Creates a PDA', () => {
2424

2525
test('Throws Error When Constructing PDA with NULL startState', () => {
2626
expect(() => {
27-
new PDA([], [], [], [],null, []);
27+
new PDA([], [], [], [], null, []);
2828
}).toThrowError();
2929
});
3030

3131
test('Throws Error When Constructing PDA with non State startState', () => {
3232
expect(() => {
33-
new PDA([], [], [], [], {id:1}, []);
33+
new PDA([], [], [], [], {id: 1}, []);
3434
}).toThrowError();
3535
});
3636

3737
test('Throws Error When Constructing PDA with NULL acceptState', () => {
3838
expect(() => {
39-
new PDA([], [], [], [],State.q0, [null]);
39+
new PDA([], [], [], [], State.q0, [null]);
4040
}).toThrowError();
4141
});
4242

4343
test('Throws Error When Constructing PDA with non State acceptState', () => {
4444
expect(() => {
45-
new PDA([], [], [], [], State.q0, [{id:1}]);
45+
new PDA([], [], [], [], State.q0, [{id: 1}]);
4646
}).toThrowError();
4747
});
4848

4949
test('Creates a PDA from transitions', () => {
5050
let acceptingState = State.q(1, true);
51-
let states = [State.q0, acceptingState];
51+
let states = [State.q0, acceptingState, State.q(2)];
5252
let inputAlphabet = [InputSymbol.EPSILON];
5353
let stackAlphabet = [StackSymbol.EMPTY_STACK];
5454
let transitions = [
55-
new Transition(State.q0, acceptingState, InputSymbol.EPSILON, StackSymbol.EMPTY_STACK, StackSymbol.EMPTY_STACK)
55+
new Transition(State.q0, acceptingState, InputSymbol.EPSILON, StackSymbol.EMPTY_STACK, StackSymbol.EMPTY_STACK),
56+
new Transition(State.q0, State.q(2), InputSymbol.EPSILON, StackSymbol.EMPTY_STACK, StackSymbol.EMPTY_STACK)
5657
];
5758
let startState = State.q0;
5859
let acceptStates = [acceptingState];
@@ -63,7 +64,7 @@ test('Creates a PDA from transitions', () => {
6364
})
6465

6566
test('Throws Error When Creating a PDA from transitions and startState isn\'t in transitions', () => {
66-
expect(()=> {
67-
PDA.fromTransitions([], State.q0)
67+
expect(() => {
68+
PDA.fromTransitions([])
6869
}).toThrowError();
6970
})

‎test/internal/pda/Transition.test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,55 +21,55 @@ test('Construct new Transition', () => {
2121

2222
test('Expect error when creating a Transition with null fromState', () => {
2323
expect(() => {
24-
new Transition(null, null, null,null,null);
24+
new Transition(null, null, null, null, null);
2525
}).toThrowError();
2626
});
2727

2828
test('Expect error when creating a Transition with non State fromState', () => {
2929
expect(() => {
30-
new Transition({id:1}, null,null,null,null);
30+
new Transition({id: 1}, null, null, null, null);
3131
}).toThrowError();
3232
});
3333

3434
test('Expect error when creating a Transition with null toState', () => {
3535
expect(() => {
36-
new Transition(State.q0, null, null,null,null);
36+
new Transition(State.q0, null, null, null, null);
3737
}).toThrowError();
3838
});
3939

4040
test('Expect error when creating a Transition with non State toState', () => {
4141
expect(() => {
42-
new Transition(State.q0, {id: 1},null,null,null);
42+
new Transition(State.q0, {id: 1}, null, null, null);
4343
}).toThrowError();
4444
});
4545

4646
test('Expect error when creating a Transition with null input', () => {
4747
expect(() => {
48-
new Transition(State.q0, State.q0, null,null,null);
48+
new Transition(State.q0, State.q0, null, null, null);
4949
}).toThrowError();
5050
});
5151

5252
test('Expect error when creating a Transition with non InputSymbol input', () => {
5353
expect(() => {
54-
new Transition(State.q0, State.q0, {id: 1},null,null);
54+
new Transition(State.q0, State.q0, {id: 1}, null, null);
5555
}).toThrowError();
5656
});
5757

5858
test('Expect error when creating a Transition with null stackHead', () => {
5959
expect(() => {
60-
new Transition(State.q0, State.q0, InputSymbol.EPSILON,null,null);
60+
new Transition(State.q0, State.q0, InputSymbol.EPSILON, null, null);
6161
}).toThrowError();
6262
});
6363

6464
test('Expect error when creating a Transition with non Symbol stackHead', () => {
6565
expect(() => {
66-
new Transition(State.q0, State.q0, InputSymbol.EPSILON, {id: 1},null);
66+
new Transition(State.q0, State.q0, InputSymbol.EPSILON, {id: 1}, null);
6767
}).toThrowError();
6868
});
6969

7070
test('Expect error when creating a Transition with null stackPush', () => {
7171
expect(() => {
72-
new Transition(State.q0, State.q0, InputSymbol.EPSILON, StackSymbol.EMPTY_STACK,null);
72+
new Transition(State.q0, State.q0, InputSymbol.EPSILON, StackSymbol.EMPTY_STACK, null);
7373
}).toThrowError();
7474
});
7575

0 commit comments

Comments
 (0)
This repository has been archived.