-
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
487 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,84 @@ | ||
import { Grader, Student } from './types'; | ||
|
||
const validStudentCorrect = | ||
` | ||
function is_odd(n) { | ||
return n % 2 === 1; | ||
} | ||
const odd_stream = stream_filter(is_odd, enum_stream(1, 50)); | ||
` | ||
|
||
const validStudentWrong = | ||
` | ||
const odd_stream = stream_filter(n => n % 2 === 1, list_to_stream(list(1, 2, 3))); | ||
` | ||
|
||
const validStudentPartial = | ||
` | ||
function is_odd(n) { | ||
return n % 2 === 1; | ||
} | ||
const odd_stream = stream_filter(is_odd, stream_append(enum_stream(1, 3), enum_stream(4, 5))); | ||
` | ||
|
||
const invalidStudentRuntime = | ||
` | ||
function is_odd(n) { | ||
return n % 2 === 1; | ||
} | ||
// Will stack overflow is_stream | ||
const odd_stream = stream_filter(is_odd, integers_from(1)); | ||
` | ||
|
||
export const student: Student = { | ||
invalid: { | ||
runtime: invalidStudentRuntime, | ||
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(); | ||
`, | ||
` | ||
function stream_testcase_c() { | ||
return !is_empty_list(stream_member(3, odd_stream)) && | ||
stream_ref(odd_stream, 1) === 3 ? 1 : 0; | ||
} | ||
stream_testcase_c(); | ||
`, | ||
` | ||
function stream_testcase_d() { | ||
return is_stream(odd_stream, 1) ? 1 : 0; | ||
} | ||
stream_testcase_d(); | ||
` | ||
] | ||
|
||
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,65 @@ | ||
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', | ||
'stream_ref', | ||
'is_stream', | ||
'integers_from', | ||
'enum_stream', | ||
'list_to_stream', | ||
'stream_append', | ||
'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'}, | ||
{'grade': 1, 'resultType': 'pass'}, | ||
{'grade': 1, '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'}, | ||
{'grade': 1, 'resultType': 'pass'}, | ||
{'grade': 1, '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'}, | ||
{'grade': 1, 'resultType': 'pass'}, | ||
{'grade': 1, 'resultType': 'pass'}, | ||
]) | ||
}) | ||
|
||
test('stream grader OK, student runtimeError', async () => { | ||
const results = await runAll(makeAwsEvent(grader.valid, student.invalid.runtime)) | ||
expect(results).toEqual([ | ||
{'grade': 1, 'resultType': 'pass'}, | ||
{'grade': 2, 'resultType': 'pass'}, | ||
{'grade': 1, 'resultType': 'pass'}, | ||
{'errors': [{'errorType': 'runtime', 'line': 3, 'location': 'grader'}], 'resultType': 'error'}, | ||
]) | ||
}) |
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.