Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
indocomsoft committed Oct 11, 2018
1 parent 2024f19 commit 0de90cb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/__tests__/examples/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const validStudentCorrect =
return n % 2 === 1;
}
const odd_stream = stream_filter(is_odd, integers_from(1));
const odd_stream = stream_filter(is_odd, enum_stream(1, 50));
`

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

const validStudentPartial =
Expand All @@ -23,10 +23,20 @@ const validStudentPartial =
const odd_stream = stream_filter(is_odd, enum_stream(1, 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: null,
syntax: null
runtime: invalidStudentRuntime,
syntax: null,
},
valid: {
correct: validStudentCorrect,
Expand All @@ -49,6 +59,18 @@ const validGrader = [
return equal(lst, list(1, 3, 5, 7, 9)) ? 2 : 0;
}
stream_testcase_b();
`,
`
function stream_testcase_c() {
return 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();
`
]

Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/test_streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const makeAwsEvent = awsEventFactory({
'stream_to_list',
'stream_take_max',
'stream_tail',
'stream_ref',
'is_stream',
'integers_from',
'enum_stream',
'equal',
Expand All @@ -25,6 +27,8 @@ test('stream grader OK, student OK, correct', async () => {
expect(results).toEqual([
{'grade': 1, 'resultType': 'pass'},
{'grade': 2, 'resultType': 'pass'},
{'grade': 1, 'resultType': 'pass'},
{'grade': 1, 'resultType': 'pass'},
])
})

Expand All @@ -33,6 +37,8 @@ test('stream grader OK, student OK, wrong', async () => {
expect(results).toEqual([
{'grade': 0, 'resultType': 'pass'},
{'grade': 0, 'resultType': 'pass'},
{'grade': 1, 'resultType': 'pass'},
{'grade': 1, 'resultType': 'pass'},
])
})

Expand All @@ -41,6 +47,17 @@ test('stream grader OK, student OK, partial', async () => {
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'},
])
})

0 comments on commit 0de90cb

Please sign in to comment.