Last active
February 9, 2017 17:03
-
-
Save caward12/81a2bd9daa34835b4a771fa558fde242 to your computer and use it in GitHub Desktop.
Week 2 and 3 Diagnostic
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
```class PizzaOven | |
def cook_pizza | |
"mmm 'za" | |
end | |
end``` | |
```class Student | |
def initialize (name) | |
@name = name | |
end | |
def name | |
@name | |
end | |
end``` This could be replaced with an attr_reader for name | |
```numbers = [1,2,3,4,5] | |
numbers.map! {|num| num*2} | |
sum = 0 | |
numbers.each {|num| sum+=num}``` | |
git init - creates new git respository for folder you are in | |
Pizza | |
```def test_that_is_tasty_returns_true | |
pie = Pizza.new | |
assert pie.is_tasty | |
end ``` | |
``` def test_what_style_of_pizza | |
pie = pizza.new | |
assert_equal "suppreme" || "mediterranean" || "cheese", pie.style | |
end ``` | |
git add . - stages files | |
git commit -m "commit message here" - commits the files | |
Student | |
```class Student | |
attr_reader :attitude :assignments | |
def initialize | |
@attitude = "cheerful" | |
@assignments = "" | |
end | |
def assign_homework(assignment) | |
assignments << assignment + ", " | |
if attitude == "cheerful" | |
attitude = "dubious" | |
elsif attitude == "dubious" | |
attitude = "perturbed" | |
elsif attitude == "perturbed" | |
attitude = "dazed" | |
else | |
attitude | |
end | |
end | |
end ``` | |
to get all students' assignments: | |
```students.assignments ``` | |
code would output: | |
"x: 4" | |
"b: 12" | |
working with files: | |
```new_file = File.open(ARGV[0], "r") | |
puts new_file.readlines ``` | |
writing files: | |
```file1 = File.open(ARGV[0], "r") | |
file1.readlines | |
writer = File.open(ARGV[1], "w") | |
writer.write(file1.readlines.count) ``` | |
corgi tests: | |
def test_it_can_be_created_with_no_arguments | |
new_corgi = Corgi.new | |
assert_instance_of Corgi, new_corgi | |
end | |
def test_it_can_be_assigned_name | |
new_corgi = Corgi.new | |
new_corgi.assign_name("Fred") | |
assert_equal "Fred", new_corgi.name | |
end | |
def test_it_can_be_asked_for_its_name | |
new_corgi = Corgi.new | |
new_corgi.assign_name("Suzy") | |
assert_equal "Suzy", new_corgi.give_name | |
end | |
def test_its_default_posture_is_standing | |
new_corgi = Corgi.new | |
assert_equal "standing", new_corgi.posture | |
end | |
def test_its_posture_can_change_to_laying | |
new_corgi = Corgi.new | |
new_corgi.lie_down | |
assert_equal "laying", new_corgi.posture | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment