-
Notifications
You must be signed in to change notification settings - Fork 83
Support Student-written Executable Examples (WiP) #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rjtsai
wants to merge
10
commits into
web-cat:staging
Choose a base branch
from
rjtsai:master
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
67dea2e
submit_01
rjtsai 94bd7ba
student tests 1
rjtsai b7b4e27
test case refactor
rjtsai 07fb80c
test case refactor edits
rjtsai 61555f2
basic student test case display
rjtsai 01cbbda
student test case display description+cosmetics
rjtsai 4b41320
Merge branch 'staging' of https://github.com/rtblast70/code-workout
rjtsai d9a3103
minor commenting
rjtsai f63a030
Merge branch 'staging' of https://github.com/web-cat/code-workout
rjtsai ea5a587
minor edits
rjtsai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,99 @@ | ||
| module TestCaseHelper | ||
|
|
||
| # if called from coding_prompt.rb, cp_answer is nil | ||
| def generate_CSV_tests(file_name, coding_prompt, cp_answer = nil) | ||
| lang = coding_prompt.language | ||
| tests = '' | ||
| if cp_answer.nil? | ||
| loc = coding_prompt.test_cases.only_dynamic | ||
| else | ||
| loc = cp_answer.student_test_cases | ||
| end | ||
| loc.each do |test_case| | ||
| tests << self.to_code(lang, test_case) | ||
| end | ||
| body = File.read('usr/resources/' + lang + '/' + lang + | ||
| 'BaseTestFile.' + Exercise.extension_of(lang)) | ||
| File.write(file_name, body % { | ||
| tests: tests, | ||
| method_name: coding_prompt.method_name, | ||
| class_name: coding_prompt.class_name | ||
| }) | ||
| end | ||
|
|
||
| # moved from test_case.rb and student_test_case.rb | ||
| def to_code(language, test_case) | ||
| inp = test_case.input | ||
| if !inp.blank? | ||
| # TODO: need to fix this to handle nested parens appropriately | ||
| inp.gsub!(/map\([^()]*\)/) do |map_expr| | ||
| map_expr.split(/"/).map.with_index{ |x, i| | ||
| if i % 2 == 0 | ||
| x.gsub(/\s*=(>?)\s*/, ', ') | ||
| else | ||
| x | ||
| end | ||
| }.join('"') | ||
| end | ||
| end | ||
| if test_case.is_a?(StudentTestCase) | ||
| coding_prompt = test_case.coding_prompt_answer.actable.prompt.specific | ||
| TEST_METHOD_TEMPLATES[language] % { | ||
| id: test_case.id.to_s, | ||
| method_name: coding_prompt.method_name, | ||
| class_name: coding_prompt.class_name, | ||
| input: inp, | ||
| expected_output: test_case.expected_output, | ||
| negative_feedback: 'check your understanding', | ||
| } | ||
| else | ||
| TEST_METHOD_TEMPLATES[language] % { | ||
| id: test_case.id.to_s, | ||
| method_name: test_case.coding_prompt.method_name, | ||
| class_name: test_case.coding_prompt.class_name, | ||
| input: inp, | ||
| expected_output: test_case.expected_output, | ||
| negative_feedback: test_case.negative_feedback, | ||
| array: ((test_case.expected_output.start_with?('new ') && | ||
| test_case.expected_output.include?('[]')) || | ||
| test_case.expected_output.start_with?('array(')) ? 'Array' : '' | ||
| } | ||
| end | ||
| end | ||
|
|
||
|
|
||
| # heredoc | ||
| # moved from test_case.rb and student_test_case.rb | ||
| TEST_METHOD_TEMPLATES = { | ||
| 'Ruby' => <<RUBY_TEST, | ||
| def test%{id} | ||
| assert_equal(%{expected_output}, @@subject.%{method_name}(%{input}), "%{negative_feedback}") | ||
| end | ||
|
|
||
| RUBY_TEST | ||
| 'Python' => <<PYTHON_TEST, | ||
| def test%{id}(self): | ||
| self.assertEqual(%{expected_output}, self.__%{method_name}(%{input})) | ||
|
|
||
| PYTHON_TEST | ||
| 'Java' => <<JAVA_TEST, | ||
| @Test | ||
| public void test_%{id}() | ||
| { | ||
| assertEquals( | ||
| "%{negative_feedback}", | ||
| %{expected_output}, | ||
| subject.%{method_name}(%{input})); | ||
| } | ||
| JAVA_TEST | ||
| 'C++' => <<CPP_TEST | ||
| void test%{id}() | ||
| { | ||
| TSM_ASSERT_EQUALS( | ||
| "%{negative_feedback}", | ||
| %{expected_output}, | ||
| subject.%{method_name}(%{input})); | ||
| } | ||
| CPP_TEST | ||
| } | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| class StudentTestCase < ActiveRecord::Base | ||
|
|
||
| # Relationships | ||
| belongs_to :coding_prompt_answer | ||
| has_one :student_test_case_result | ||
|
|
||
| def record_result(answer, test_results_array) | ||
| tcr = StudentTestCaseResult.new( | ||
| test_case_id: self.id, | ||
| coding_prompt_answer: answer, | ||
| pass: (test_results_array.length == 8 && test_results_array[7].to_i == 1) | ||
| ) | ||
|
|
||
| if !test_results_array[5].blank? | ||
| exception_name = test_results_array[6] #.sub(/^.*\./, '') | ||
| if !(['AssertionFailedError', | ||
| 'AssertionError', | ||
| 'ComparisonFailure', | ||
| 'ReflectionSupportError'].include?(exception_name) || | ||
| (exception_name == 'Exception' && | ||
| test_results_array[6].start_with?('test timed out'))) || | ||
| test_results_array[6].blank? || | ||
| "null" == test_results_array[6] | ||
| tcr.feedback = exception_name | ||
| end | ||
| end | ||
| tcr.save! | ||
| end | ||
|
|
||
| def display_description() | ||
| self.description | ||
| end | ||
|
|
||
| end |
This file contains hidden or 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,12 @@ | ||
| class StudentTestCaseResult < ActiveRecord::Base | ||
|
|
||
| # Relationships | ||
| belongs_to :coding_prompt_answer, inverse_of: :student_test_case_results | ||
| belongs_to :student_test_case, class_name: "StudentTestCase", | ||
| foreign_key: :test_case_id, inverse_of: :student_test_case_result | ||
|
|
||
| def display_description | ||
| student_test_case.display_description() | ||
| end | ||
|
|
||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.