From 12bbbe569fb4855017dd721404fb31f754b5a444 Mon Sep 17 00:00:00 2001 From: Maxwell Baird Date: Thu, 30 Jan 2020 13:23:56 -0700 Subject: [PATCH 1/8] added a way to calc the standard deviation --- lib/standard_deviation.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/standard_deviation.rb b/lib/standard_deviation.rb index e17b03a..2a02aa6 100644 --- a/lib/standard_deviation.rb +++ b/lib/standard_deviation.rb @@ -1,5 +1,33 @@ ages = [24, 30, 18, 20, 41] # Your code here for calculating the standard deviation +def standard_deviation(dev_array) + step1_value = 0.0 + dev_array.each do |value| + step1_value += value + end + step3_value = 0.0 + step3_value = step1_value / dev_array.size + + step4_array = [] + dev_array.each do |value| + step4_array << (value - step3_value) + end + + step5_array = [] + step4_array.each do |value| + step5_array << (value * value) + end + + step6_sum = 0 + step5_array.each do |value| + step6_sum += value + end + step7_divide = step6_sum / dev_array.size + + total = Math.sqrt(step7_divide) + puts total +end # When you find the standard deviation, print it out +standard_deviation(ages) From ab6f59a7362036661af364176ec1fd927e416885 Mon Sep 17 00:00:00 2001 From: Maxwell Baird Date: Thu, 30 Jan 2020 13:31:23 -0700 Subject: [PATCH 2/8] created a test to if event exist and also created a class called event --- lib/event.rb | 8 ++++++++ test/event_test.rb | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 lib/event.rb create mode 100644 test/event_test.rb diff --git a/lib/event.rb b/lib/event.rb new file mode 100644 index 0000000..e7a2ca7 --- /dev/null +++ b/lib/event.rb @@ -0,0 +1,8 @@ +class Event + + attr_reader :name, :ages + def initialize(event_name, ages_for_event) + @name = event_name + @ages = ages_for_event + end +end diff --git a/test/event_test.rb b/test/event_test.rb new file mode 100644 index 0000000..64cb2f8 --- /dev/null +++ b/test/event_test.rb @@ -0,0 +1,11 @@ +require 'minitest/autorun' +require 'minitest/pride' +require './lib/event' + +class EventTest < Minitest::Test + + def test_if_event_exist + event = Event.new("Curling", [24, 30, 18, 20, 41]) + assert_instance_of Event, event + end +end From ddf58e2feffcf9ca9cecd60f799ef88f25fbda20 Mon Sep 17 00:00:00 2001 From: Maxwell Baird Date: Thu, 30 Jan 2020 13:39:15 -0700 Subject: [PATCH 3/8] added test for max_age and then add the method for max_age to event.rb --- lib/event.rb | 14 ++++++++++++++ test/event_test.rb | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/event.rb b/lib/event.rb index e7a2ca7..9ff9d9a 100644 --- a/lib/event.rb +++ b/lib/event.rb @@ -5,4 +5,18 @@ def initialize(event_name, ages_for_event) @name = event_name @ages = ages_for_event end + + def max_age + max_age_holder = 0 + @ages.each do |age| + + if age > max_age_holder + max_age_holder = age + end + + end + max_age_holder + end + + end diff --git a/test/event_test.rb b/test/event_test.rb index 64cb2f8..adeced1 100644 --- a/test/event_test.rb +++ b/test/event_test.rb @@ -8,4 +8,24 @@ def test_if_event_exist event = Event.new("Curling", [24, 30, 18, 20, 41]) assert_instance_of Event, event end + + def test_if_event_has_name + event = Event.new("Curling", [24, 30, 18, 20, 41]) + assert_equal "Curling", event.name + end + + def test_if_event_has_ages + event = Event.new("Curling", [24, 30, 18, 20, 41]) + assert_equal [24, 30, 18, 20, 41], event.ages + end + + def test_event_max_age + event = Event.new("Curling", [24, 30, 18, 20, 41]) + assert_equal 41, event.max_age + end + + def test_event_min_age + event = Event.new("Curling", [24, 30, 18, 20, 41]) + assert_equal 18, event.max_age + end end From 9e25730a7c4912543e8b2b5437fc673a2a6d2745 Mon Sep 17 00:00:00 2001 From: Maxwell Baird Date: Thu, 30 Jan 2020 13:42:06 -0700 Subject: [PATCH 4/8] added a test for event min_age and the method min_age for event.rb --- lib/event.rb | 13 +++++++++++++ test/event_test.rb | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/event.rb b/lib/event.rb index 9ff9d9a..11e0ed5 100644 --- a/lib/event.rb +++ b/lib/event.rb @@ -18,5 +18,18 @@ def max_age max_age_holder end + def min_age + min_age_holder = 999 + + @ages.each do |age| + + if age < min_age_holder + min_age_holder = age + end + + end + + min_age_holder + end end diff --git a/test/event_test.rb b/test/event_test.rb index adeced1..05545a0 100644 --- a/test/event_test.rb +++ b/test/event_test.rb @@ -26,6 +26,6 @@ def test_event_max_age def test_event_min_age event = Event.new("Curling", [24, 30, 18, 20, 41]) - assert_equal 18, event.max_age + assert_equal 18, event.min_age end end From 1c689989e0cf05d40796f28269ccfdc75e7541ad Mon Sep 17 00:00:00 2001 From: Maxwell Baird Date: Thu, 30 Jan 2020 13:44:48 -0700 Subject: [PATCH 5/8] added a test for average_age method --- test/event_test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/event_test.rb b/test/event_test.rb index 05545a0..aa9eb61 100644 --- a/test/event_test.rb +++ b/test/event_test.rb @@ -28,4 +28,9 @@ def test_event_min_age event = Event.new("Curling", [24, 30, 18, 20, 41]) assert_equal 18, event.min_age end + + def test_event_average_age + event = Event.new("Curling", [24, 30, 18, 20, 41]) + assert_equal 26.6, event.average_age + end end From 172714e7ef6e9c9d119ff4b3eba9f5d080b678b2 Mon Sep 17 00:00:00 2001 From: Maxwell Baird Date: Thu, 30 Jan 2020 14:03:11 -0700 Subject: [PATCH 6/8] added the method standard deviation and the test for it --- lib/event.rb | 39 +++++++++++++++++++++++++++++++++++++++ lib/games_runner.rb | 0 test/event_test.rb | 5 +++++ 3 files changed, 44 insertions(+) create mode 100644 lib/games_runner.rb diff --git a/lib/event.rb b/lib/event.rb index 11e0ed5..9ff7267 100644 --- a/lib/event.rb +++ b/lib/event.rb @@ -32,4 +32,43 @@ def min_age min_age_holder end + def average_age + average_age_holder = 0.0 + + @ages.each do |age| + average_age_holder += age + end + + value = average_age_holder / @ages.size + value.round(2) + end + + def standard_deviation_age + step1_value = 0.0 + @ages.each do |value| + step1_value += value + end + step3_value = 0.0 + step3_value = step1_value / @ages.size + + step4_array = [] + @ages.each do |value| + step4_array << (value - step3_value) + end + + step5_array = [] + step4_array.each do |value| + step5_array << (value * value) + end + + step6_sum = 0 + step5_array.each do |value| + step6_sum += value + end + step7_divide = step6_sum / @ages.size + + total = Math.sqrt(step7_divide) + total.round(2) + end + end diff --git a/lib/games_runner.rb b/lib/games_runner.rb new file mode 100644 index 0000000..e69de29 diff --git a/test/event_test.rb b/test/event_test.rb index aa9eb61..e424a37 100644 --- a/test/event_test.rb +++ b/test/event_test.rb @@ -33,4 +33,9 @@ def test_event_average_age event = Event.new("Curling", [24, 30, 18, 20, 41]) assert_equal 26.6, event.average_age end + + def test_event_standard_deviation + event = Event.new("Curling", [24, 30, 18, 20, 41]) + assert_equal 8.28, event.standard_deviation_age + end end From 98551436001a1e89c45c2383b1fd3e9d711bf5c8 Mon Sep 17 00:00:00 2001 From: Maxwell Baird Date: Thu, 30 Jan 2020 15:07:50 -0700 Subject: [PATCH 7/8] created the game runner --- lib/event.rb | 7 ++++--- lib/games_runner.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/event.rb b/lib/event.rb index 9ff7267..1fa0f59 100644 --- a/lib/event.rb +++ b/lib/event.rb @@ -19,7 +19,7 @@ def max_age end def min_age - min_age_holder = 999 + min_age_holder = 99999999 @ages.each do |age| @@ -45,11 +45,12 @@ def average_age def standard_deviation_age step1_value = 0.0 + divide_value = @ages.size @ages.each do |value| step1_value += value end step3_value = 0.0 - step3_value = step1_value / @ages.size + step3_value = step1_value / divide_value step4_array = [] @ages.each do |value| @@ -65,7 +66,7 @@ def standard_deviation_age step5_array.each do |value| step6_sum += value end - step7_divide = step6_sum / @ages.size + step7_divide = step6_sum / divide_value total = Math.sqrt(step7_divide) total.round(2) diff --git a/lib/games_runner.rb b/lib/games_runner.rb index e69de29..4c951e6 100644 --- a/lib/games_runner.rb +++ b/lib/games_runner.rb @@ -0,0 +1,30 @@ +require './lib/event' +require './lib/games' + +puts "What year is it?" +year = gets.chomp +game = Games.new(year) +puts "Type in the name of the event and then the ages of the players." +puts "Type quit to see a summary" +input = '' +puts "What is the name of the event? Type quit here to see the summary" +input = gets.chomp +while input != "quit" do + ages_array = [] + puts "Type in the age of one player. Type in quit to create a different event" + age_input = '' + if input != 'quit' + while age_input != 'quit' do + puts "Age of a player: " + age_input = gets.chomp + if age_input != 'quit' + ages_array << age_input.to_i + end # age_input != 'quit' + end # age_input != 'quit' do + end # input != 'quit' + event = Event.new(input, ages_array) + game.add_event(event) + puts "What is the name of the next event? Type quit here to see the summary" + input = gets.chomp +end #while input != "quit" do +p game.summary From 3ad83980358563a3b66477e879ac38b73128735e Mon Sep 17 00:00:00 2001 From: Maxwell Baird Date: Thu, 30 Jan 2020 15:20:02 -0700 Subject: [PATCH 8/8] fixed presentation of summary --- lib/games_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/games_runner.rb b/lib/games_runner.rb index 4c951e6..882f05d 100644 --- a/lib/games_runner.rb +++ b/lib/games_runner.rb @@ -27,4 +27,4 @@ puts "What is the name of the next event? Type quit here to see the summary" input = gets.chomp end #while input != "quit" do -p game.summary +puts game.summary