-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
445 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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 |
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
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,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 | ||
} |
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,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'}, | ||
]) | ||
}) | ||
|
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
Oops, something went wrong.