Skip to content

Commit

Permalink
Merge 2024f19 into 304261e
Browse files Browse the repository at this point in the history
  • Loading branch information
indocomsoft committed Oct 10, 2018
2 parents 304261e + 2024f19 commit 90e2b42
Show file tree
Hide file tree
Showing 6 changed files with 445 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: node_js
node_js:
- 9
- 10
cache: yarn
branches:
except:
- /^no-ci.*$/
script:
- yarn test
- yarn test-coveralls
- yarn typecheck
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "./scripts/build.sh",
"typecheck": "tsc --noEmit",
"test": "TIMEOUT=2000 jest --env=node",
"test-coveralls": "TIMEOUT=2000 jest --env=node --coverage --coverageReporters=text-lcov | coveralls"
"test-coveralls": "TIMEOUT=2000 jest --env=node --coverage --coverageReporters=text-lcov --forceExit | coveralls"
},
"dependencies": {
"@ericandrewlewis/bitmap": "^1.0.0",
Expand Down
61 changes: 61 additions & 0 deletions src/__tests__/examples/streams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Grader, Student } from './types';

const validStudentCorrect =
`
function is_odd(n) {
return n % 2 === 1;
}
const odd_stream = stream_filter(is_odd, integers_from(1));
`

const validStudentWrong =
`
const odd_stream = stream_filter(n => n % 2 === 1, enum_stream(0, 1));
`

const validStudentPartial =
`
function is_odd(n) {
return n % 2 === 1;
}
const odd_stream = stream_filter(is_odd, enum_stream(1, 5));
`

export const student: Student = {
invalid: {
runtime: null,
syntax: null
},
valid: {
correct: validStudentCorrect,
wrong: validStudentWrong,
partial: validStudentPartial
}
}

const validGrader = [
`
function stream_testcase_a() {
const lst = stream_to_list(stream_take_max(odd_stream, 3));
return equal(lst, list(1, 3, 5)) ? 1 : 0;
}
stream_testcase_a();
`,
`
function stream_testcase_b() {
const lst = stream_to_list(stream_take_max(odd_stream, 5));
return equal(lst, list(1, 3, 5, 7, 9)) ? 2 : 0;
}
stream_testcase_b();
`
]

export const grader: Grader = {
invalid: {
runtime: null,
syntax: null
},
valid: validGrader
}
46 changes: 46 additions & 0 deletions src/__tests__/test_streams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { grader, student } from './examples/streams'
import { awsEventFactory } from './helpers'
import { runAll } from '../index'

const makeAwsEvent = awsEventFactory({
chapter: 3,
external: {
name: 'NONE',
symbols: [
'stream_filter',
'stream_to_list',
'stream_take_max',
'stream_tail',
'integers_from',
'enum_stream',
'equal',
'list',
]
},
globals: []
})

test('stream grader OK, student OK, correct', async () => {
const results = await runAll(makeAwsEvent(grader.valid, student.valid.correct))
expect(results).toEqual([
{'grade': 1, 'resultType': 'pass'},
{'grade': 2, 'resultType': 'pass'},
])
})

test('stream grader OK, student OK, wrong', async () => {
const results = await runAll(makeAwsEvent(grader.valid, student.valid.wrong))
expect(results).toEqual([
{'grade': 0, 'resultType': 'pass'},
{'grade': 0, 'resultType': 'pass'},
])
})

test('stream grader OK, student OK, partial', async () => {
const results = await runAll(makeAwsEvent(grader.valid, student.valid.partial))
expect(results).toEqual([
{'grade': 1, 'resultType': 'pass'},
{'grade': 0, 'resultType': 'pass'},
])
})

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const runAll = async (event: AwsEvent): Promise<Output[]> => {
require('./util.js')
require('./list.js')
require('./tree.js')
require('./streams/streams.js')
if (event.library && event.library.external) {
switch(event.library.external.name) {
case 'TWO_DIM_RUNES': {}
Expand Down
Loading

0 comments on commit 90e2b42

Please sign in to comment.