-
Notifications
You must be signed in to change notification settings - Fork 5
Created an autograder for R programming language #17
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# Makefile to manage the example Hello Lab | ||
# | ||
|
||
# Get the name of the lab directory | ||
LAB = $(notdir $(PWD)) | ||
|
||
all: handout handout-tarfile | ||
|
||
handout: | ||
# Rebuild the handout directory that students download | ||
(rm -rf $(LAB)-handout; mkdir $(LAB)-handout) | ||
cp -p src/README-handout $(LAB)-handout/README | ||
cp -p src/calculator.R-handout $(LAB)-handout/calculator.R | ||
cp -p src/driver.R $(LAB)-handout/driver.R | ||
cp -p src/tests.R-handout $(LAB)-handout/tests.R | ||
|
||
handout-tarfile: handout | ||
# Build *-handout.tar and autograde.tar | ||
tar cvf $(LAB)-handout.tar $(LAB)-handout | ||
tar cvf autograde.tar src | ||
|
||
clean: | ||
# Clean the entire lab directory tree. Note that you can run | ||
# "make clean; make" at any time while the lab is live with no | ||
# adverse effects. | ||
rm -f *~ *.tar | ||
rm -rf $(LAB)-handout | ||
rm -f autograde.tar | ||
# | ||
# CAREFULL!!! This will delete all student records in the logfile and | ||
# in the handin directory. Don't run this once the lab has started. | ||
# Use it to clean the directory when you are starting a new version | ||
# of the lab from scratch, or when you are debugging the lab prior | ||
# to releasing it to the students. | ||
# | ||
cleanallfiles: | ||
# Reset the lab from scratch. | ||
make clean | ||
rm -f log.txt | ||
rm -rf handin/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
For this lab, you should write a Python program, called "twosum.py". | ||
|
||
Given an array of integers `nums` and an integer `target`, your program should return indices of the two numbers such that they add up to target. | ||
|
||
You may assume that each input has at least one solution, and you may not use the same element twice. | ||
|
||
You can return the answer in any order. Your solution should be in O(n) time for full credit. | ||
|
||
**Example 1:** | ||
|
||
``` | ||
Input: nums = [2,7,11,15], target = 9 | ||
Output: [0,1] | ||
Output: Because nums[0] + nums[1] == 9, we return [0, 1]. | ||
``` | ||
|
||
``` | ||
Input: nums = [3, 2, 4], target = 6 | ||
Output: [1, 2] | ||
Output: Because nums[1] + nums[2] == 6, we return [1, 2]. | ||
``` | ||
|
||
To compile your work: | ||
linux> make clean; make; | ||
|
||
Files: | ||
README This file | ||
twosum.py Empty Python file that you will edit | ||
driver.py Autograding file used to test your submission | ||
tests.py File for writing custom test cases | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add <-function(a,b){ | ||
return 0 | ||
} | ||
subtract <-function(a,b){ | ||
return 0 | ||
} | ||
multiplication <-function(a,b){ | ||
return 0 | ||
} | ||
division <-function(a,b){ | ||
return 0 | ||
} | ||
Comment on lines
+1
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement arithmetic operations. The functions If these are intended as stubs for now, ensure that this is documented and that there is a plan to implement the actual logic. add <- function(a, b) {
return(a + b)
}
subtract <- function(a, b) {
return(a - b)
}
multiplication <- function(a, b) {
return(a * b)
}
division <- function(a, b) {
if (b == 0) {
stop("Division by zero error")
}
return(a / b)
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||||||
source("calculator.R") | ||||||||||
source("tests.R") | ||||||||||
|
||||||||||
run_testcases <- function(test_cases) { | ||||||||||
is_passed <- 0 | ||||||||||
for (case in test_cases) { | ||||||||||
print(case$description) | ||||||||||
a <- case$inputs[1] | ||||||||||
b <- case$inputs[1] | ||||||||||
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix input assignment for test cases. The variable - b <- case$inputs[1]
+ b <- case$inputs[2] Committable suggestion
Suggested change
|
||||||||||
|
||||||||||
if ((a + b == add(a, b)) && | ||||||||||
(a - b == subtract(a, b)) && | ||||||||||
(a * b == multiplication(a, b)) && | ||||||||||
(a / b == division(a, b))) { | ||||||||||
Comment on lines
+10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for division by zero. Currently, there is no check for division by zero, which could cause a runtime error. if (b == 0) {
print('---Failed! Division by zero---')
} else if ((a + b == add(a, b)) &&
(a - b == subtract(a, b)) &&
(a * b == multiplication(a, b)) &&
(a / b == division(a, b))) {
is_passed <- is_passed + 1
print('---Passed!---')
} else {
print('---Failed!---')
} |
||||||||||
is_passed <- is_passed + 1 | ||||||||||
print('---Passed!---') | ||||||||||
} else { | ||||||||||
print('---Failed!---') | ||||||||||
} | ||||||||||
} | ||||||||||
return(is_passed) | ||||||||||
} | ||||||||||
|
||||||||||
# Calculate the score | ||||||||||
test_score <- (run_testcases(test_cases) / length(test_cases)) * 100 | ||||||||||
cat(sprintf('{"scores": {"Correctness": %f}}', test_score)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#Write your custom test cases in this file. | ||
|
||
#Each test case is formatted as an array of 3 elements: | ||
#0. test case number | ||
#1. Integer list | ||
#2. Output | ||
|
||
test_cases <- list( | ||
list(description = "case 1", inputs = c(1, 2)), | ||
list(description = "case 2", inputs = c(6, 3)) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require "AssessmentBase.rb" | ||
|
||
module Hello | ||
include AssessmentBase | ||
|
||
def assessmentInitialize(course) | ||
super("hello",course) | ||
@problems = [] | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
general: | ||
name: calculator | ||
description: 'Basic calculator functions' | ||
display_name: calculator | ||
handin_filename: calculator.R | ||
handin_directory: handin | ||
max_grace_days: 0 | ||
handout: calculator-handout.tar | ||
writeup: writeup/calculator.html | ||
max_submissions: -1 | ||
disable_handins: false | ||
max_size: 2 | ||
category_name: Lab | ||
problems: | ||
- name: Correctness | ||
description: '' | ||
max_score: 100.0 | ||
optional: false | ||
autograder: | ||
autograde_timeout: 180 | ||
autograde_image: autograding_r | ||
release_score: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<h1>calculator Lab</h1> | ||
|
||
<h2>Assessment Language</h2> | ||
R | ||
|
||
<h2>Autograder Language</h2> | ||
R | ||
|
||
<h2>Autograding Environment Packages</h2> | ||
Rscript is needed for the autograding environment. | ||
|
||
<h2>Assessment Scenario</h2> | ||
In this lab, students are required to implement functions add(), Subtract(), | ||
multiplication(), and division(). | ||
which takes in two integers as input. | ||
The function returns the answer. | ||
|
||
<h2>Hand-in Format</h2> | ||
calculator.R | ||
|
||
<h2>Autograder.tar directory content</h2> | ||
Makefile Builds the lab from src/ | ||
autograde-Makefile Makefile that runs the autograder | ||
src/ Contains all src files and solutions | ||
writeup/ Lab writeup that students view from Autolab | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
all: | ||
tar xvf autograde.tar | ||
cp -r calculator.R src | ||
(cd src && Rscript driver.R;) | ||
|
||
clean: | ||
rm -rf *~ src |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
For this lab, you should write a R program, called "calculator.R". | ||
|
||
Given two integers a, b, your program should return indices of the final result as a single integer. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
For this lab, you should write a R program, called "calculator.R". | ||
|
||
Given two integers a, b, your program should return indices of the final result as a single integer. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add <-function(a,b){ | ||
return(a+b) | ||
} | ||
subtract <-function(a,b){ | ||
return(a-b) | ||
} | ||
multiplication <-function(a,b){ | ||
return(a*b) | ||
} | ||
division <-function(a,b){ | ||
return(a/b) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add <-function(a,b){ | ||
return 0 | ||
} | ||
subtract <-function(a,b){ | ||
return 0 | ||
} | ||
multiplication <-function(a,b){ | ||
return 0 | ||
} | ||
division <-function(a,b){ | ||
return 0 | ||
} | ||
Comment on lines
+1
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement arithmetic operations in functions. The functions Would you like guidance on how to implement these functions, or should I open a GitHub issue to track this task? |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||||||
source("calculator.R") | ||||||||||
source("tests.R") | ||||||||||
|
||||||||||
run_testcases <- function(test_cases) { | ||||||||||
is_passed <- 0 | ||||||||||
for (case in test_cases) { | ||||||||||
print(case$description) | ||||||||||
a <- case$inputs[1] | ||||||||||
b <- case$inputs[1] | ||||||||||
Comment on lines
+8
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect variable assignment. The variable - b <- case$inputs[1]
+ b <- case$inputs[2] Committable suggestion
Suggested change
|
||||||||||
|
||||||||||
if ((a + b == add(a, b)) && | ||||||||||
(a - b == subtract(a, b)) && | ||||||||||
(a * b == multiplication(a, b)) && | ||||||||||
(a / b == division(a, b))) { | ||||||||||
is_passed <- is_passed + 1 | ||||||||||
print('---Passed!---') | ||||||||||
} else { | ||||||||||
print('---Failed!---') | ||||||||||
} | ||||||||||
} | ||||||||||
return(is_passed) | ||||||||||
} | ||||||||||
|
||||||||||
# Calculate the score | ||||||||||
test_score <- (run_testcases(test_cases) / length(test_cases)) * 100 | ||||||||||
cat(sprintf('{"scores": {"Correctness": %f}}', test_score)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Write your custom test cases in this file. | ||
|
||
test_cases <- list( | ||
list(description = "case 1", inputs = c(1, 2)), | ||
list(description = "case 2", inputs = c(6, 3)) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#Write your custom test cases in this file. | ||
|
||
#Each test case is formatted as an array of 3 elements: | ||
#0. test case number | ||
#1. Integer list | ||
#2. Output | ||
|
||
test_cases <- list( | ||
list(description = "case 1", inputs = c(1, 2)), | ||
list(description = "case 2", inputs = c(6, 3)) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<h2>Calculator Lab</h2> | ||
|
||
In this lab, you will write a R program, called <kbd>calcualtor.R</kbd> which performs addition, subtraction, multiplication and | ||
division. | ||
|
||
<p> | ||
Download the lab materials from Autolab using the "Download handout" link. | ||
|
||
<p> | ||
Submit your Calculator.R file to Autolab using the "Submit file" link. | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.