transferred Code Ocean from original repository to GitHub

This commit is contained in:
Hauke Klement
2015-01-22 09:51:49 +01:00
commit 4cbf9970b1
683 changed files with 11979 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="index.js"></script>
</head>
<body>
<h1>HTML5 Audio & Video</h1>
</body>
</html>

View File

@ -0,0 +1,27 @@
require 'rack/file'
require 'capybara/rspec'
AUDIO_FILENAME = 'chai.ogg'
VIDEO_FILENAME = 'devstories.mp4'
Capybara.app = Rack::File.new(File.dirname(__FILE__))
describe 'index.html', type: :feature do
before(:each) { visit('index.html') }
it 'contains an audio element' do
expect(page).to have_css('audio')
end
it 'plays the correct audio file' do
expect(page).to have_css("audio[src='#{AUDIO_FILENAME}']")
end
it 'contains a video element' do
expect(page).to have_css('video')
end
it 'plays the correct video file' do
expect(page).to have_css("video[src='#{VIDEO_FILENAME}']")
end
end

View File

@ -0,0 +1,3 @@
$(function() {
//
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

24
db/seeds/development.rb Normal file
View File

@ -0,0 +1,24 @@
# consumers
FactoryGirl.create(:consumer)
FactoryGirl.create(:consumer, name: 'openSAP')
# users
%w[admin external_user teacher].each { |factory_name| FactoryGirl.create(factory_name) }
# execution environments
ExecutionEnvironment.create_factories
# errors
Error.create_factories
# exercises
@exercises = find_factories_by_class(Exercise).map(&:name).map { |factory_name| [factory_name, FactoryGirl.create(factory_name)] }.to_h
# file types
FileType.create_factories
# hints
Hint.create_factories
# submissions
FactoryGirl.create(:submission, exercise: @exercises[:fibonacci])

View File

@ -0,0 +1,5 @@
def even(x):
pass
def odd(x):
pass

View File

@ -0,0 +1,15 @@
from exercise import *
import unittest
class ExerciseTests(unittest.TestCase):
def test_even(self):
for x in [1, 3, 5, 7, 9]:
self.assertFalse(even(x))
for x in [2, 4, 6, 8, 10]:
self.assertTrue(even(x))
def test_odd(self):
for x in [1, 3, 5, 7, 9]:
self.assertTrue(odd(x))
for x in [2, 4, 6, 8, 10]:
self.assertFalse(odd(x))

View File

@ -0,0 +1,5 @@
def even(x):
return x % 2 == 0
def odd(x):
return not even(x)

View File

@ -0,0 +1,2 @@
def fibonacci(n)
end

View File

@ -0,0 +1,15 @@
require './exercise'
describe '#fibonacci' do
it 'is defined' do
expect { method(:fibonacci) }.not_to raise_error
end
it 'has the correct arity' do
expect(method(:fibonacci).arity).to eq(1)
end
it 'returns a number' do
expect(fibonacci(1)).to be_an(Integer)
end
end

View File

@ -0,0 +1,9 @@
require './exercise'
describe '#fibonacci' do
it 'works recursively' do
@n = 16
expect(self).to receive(:fibonacci).and_call_original.at_least(@n ** 2).times
fibonacci(@n)
end
end

View File

@ -0,0 +1,16 @@
require './exercise'
require './reference'
describe '#fibonacci' do
SAMPLE_COUNT = 32
let(:reference) { Class.new.extend(Reference) }
SAMPLE_COUNT.times do |i|
instance_eval do
it "obtains the correct result for input #{i}" do
expect(fibonacci(i)).to eq(reference.fibonacci(i))
end
end
end
end

View File

@ -0,0 +1,5 @@
module Reference
def fibonacci(n)
n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2)
end
end

2
db/seeds/files/data.txt Normal file
View File

@ -0,0 +1,2 @@
Foo
Bar

View File

@ -0,0 +1,6 @@
SOURCE_FILENAME = 'data.txt'
TARGET_FILENAME = 'copy.txt'
def copy_file
# Implement this method.
end

View File

@ -0,0 +1,21 @@
require './exercise'
describe '#write_to_file' do
before(:each) do
@file_content = File.new(SOURCE_FILENAME, 'r').read
write_to_file
end
it 'preserves the source file' do
expect(File.exist?(SOURCE_FILENAME)).to be true
expect(File.new(SOURCE_FILENAME, 'r').read).to eq(@file_content)
end
it 'creates the target file' do
expect(File.exist?(TARGET_FILENAME)).to be true
end
it 'copies the file content' do
expect(File.new(TARGET_FILENAME, 'r').read).to eq(@file_content)
end
end

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="index.js"></script>
</head>
<body>
<h1>HTML5 Geolocation</h1>
<button id="locate">Locate me</button>
</body>
</html>

View File

@ -0,0 +1,3 @@
$(function() {
var button = $('#locate');
});

View File

View File

@ -0,0 +1,6 @@
describe 'Exercise' do
it "outputs 'Hello World" do
expect(STDOUT).to receive(:puts).with('Hello World')
require './exercise'
end
end

7
db/seeds/math/Makefile Normal file
View File

@ -0,0 +1,7 @@
run:
javac org/example/RecursiveMath.java
java org/example/RecursiveMath
test:
javac -cp .:/usr/java/lib/hamcrest-core-1.3.jar:/usr/java/lib/junit-4.11.jar org/example/${FILENAME}
java -cp .:/usr/java/lib/hamcrest-core-1.3.jar:/usr/java/lib/junit-4.11.jar org.junit.runner.JUnitCore org.example.${CLASS_NAME}

View File

@ -0,0 +1,12 @@
package org.example;
public class RecursiveMath {
public static void main(String[] args) {
//
}
public static double power(int base, int exponent) {
return 42;
}
}

View File

@ -0,0 +1,26 @@
package org.example;
import java.lang.Math.*;
import org.example.RecursiveMath;
import org.junit.*;
public class RecursiveMathTest1 {
@Test
public void methodIsDefined() {
boolean methodIsDefined = false;
try {
RecursiveMath.power(1, 1);
methodIsDefined = true;
} catch (NoSuchMethodError error) {
//
}
org.junit.Assert.assertTrue("RecursiveMath does not define 'power'.", methodIsDefined);
}
@Test
public void methodReturnsDouble() {
Object result = RecursiveMath.power(1, 1);
org.junit.Assert.assertTrue("Your method has the wrong return type.", result instanceof Double);
}
}

View File

@ -0,0 +1,23 @@
package org.example;
import java.lang.Math.*;
import org.example.RecursiveMath;
import org.junit.*;
public class RecursiveMathTest2 {
@Test
public void exponentZero() {
org.junit.Assert.assertEquals("Incorrect result for exponent 0.", 1, RecursiveMath.power(42, 0), 0);
}
@Test
public void negativeExponent() {
org.junit.Assert.assertEquals("Incorrect result for exponent -1.", Math.pow(2, -1), RecursiveMath.power(2, -1), 0);
}
@Test
public void positiveExponent() {
org.junit.Assert.assertEquals("Incorrect result for exponent 4.", Math.pow(2, 4), RecursiveMath.power(2, 4), 0);
}
}

View File

@ -0,0 +1,9 @@
var isPrime = function(number) {
return true;
};
var printPrimes = function(count) {
};
printPrimes();

37
db/seeds/production.rb Normal file
View File

@ -0,0 +1,37 @@
require 'highline/import'
# consumers
FactoryGirl.create(:consumer)
# users
email = ask('Enter admin email: ')
passwords = ['password', 'password confirmation'].map do |attribute|
ask("Enter admin #{attribute}: ") { |question| question.echo = false }
end
if passwords.uniq.length == 1
FactoryGirl.create(:admin, email: email, name: 'Administrator', password: passwords.first)
else
abort('Passwords do not match!')
end
# execution environments
ExecutionEnvironment.create_factories
# exercises
Exercise.create_factories
# file types
FileType.create_factories
# hints
Hint.create_factories
# change all resources' author
[ExecutionEnvironment, Exercise, FileType].each do |model|
model.update_all(user_id: InternalUser.first.id)
end
# delete temporary users
InternalUser.where.not(id: InternalUser.first.id).delete_all

View File

@ -0,0 +1,12 @@
require 'sqlite3'
REFERENCE_QUERY = File.new('reference.sql', 'r').read
STUDENT_QUERY = File.new('exercise.sql', 'r').read
database = SQLite3::Database.new('/database.db')
missing_tuples = database.execute(REFERENCE_QUERY) - database.execute(STUDENT_QUERY)
unexpected_tuples = database.execute(STUDENT_QUERY) - database.execute(REFERENCE_QUERY)
puts("Missing tuples: #{missing_tuples}")
puts("Unexpected tuples: #{unexpected_tuples}")

View File

View File

@ -0,0 +1 @@
SELECT * FROM people WHERE name LIKE '% Doe';

0
db/seeds/tdd/exercise.rb Normal file
View File

View File

@ -0,0 +1,5 @@
describe 'Exercise' do
it 'includes a successful example' do
expect(true).to be true
end
end

View File

@ -0,0 +1,11 @@
Write a method `palindrome?` that outputs whether a given input is a palindromic word.
Write tests to verify that your method works correctly for normal words, empty inputs, and malformed inputs.
#### Expected Behavior:
`palindrome?('noon') => true`
`palindrome?('hello') => false`
`palindrome?(42) => false`

7
db/seeds/web_app/app.rb Normal file
View File

@ -0,0 +1,7 @@
require 'sinatra'
set :bind, '0.0.0.0'
get '/' do
'Hello, World!'
end