Browse Source

Fix coding style

master
Arthur POULET 3 years ago
parent
commit
9739e3d42c
No known key found for this signature in database GPG Key ID: FC154EA63FF5D8BC
  1. 6
      spec/math/frequency.cr
  2. 4
      spec/math/median.cr
  3. 1
      spec/math/quartile.cr
  4. 2
      src/lib/math/frequency.cr
  5. 2
      src/lib/math/median.cr
  6. 2
      src/lib/math/quartile.cr

6
spec/math/frequency.cr

@ -2,10 +2,10 @@ FREQ_LIMIT = 100
describe Math::Frequency do
it "test trivia" do
([]of Int32).frequency_of(0).should eq 0.0
([] of Int32).frequency_of(0).should eq 0.0
[0, 1, 2, 3].frequency_of(0).should eq 0.25
[0, 0, 1, 2, 3].frequency_of(0).should eq 0.40
[0, 0, 1, 2, 3].all_frequencies.should eq({ 0 => 0.4, 1 => 0.2, 2 => 0.2, 3 => 0.2 })
[0, 0, 1, 2, 3].all_frequencies.should eq({0 => 0.4, 1 => 0.2, 2 => 0.2, 3 => 0.2})
# allfreq1 = [0, 0, 1, 2, 3].all_frequencies(2)
# allfreq1[1].should eq 0.4
# allfreq1.size.should eq 2
@ -29,6 +29,6 @@ describe Math::Frequency do
(arr.frequency_of(0) <= arr_more.frequency_of(0)).should be_true
end
[0, 0, 0, 0, 1, 1, 1, 2, 2, 3].all_frequencies.should eq({ 0 => 0.4, 1 => 0.3, 2 => 0.2, 3 => 0.1 })
[0, 0, 0, 0, 1, 1, 1, 2, 2, 3].all_frequencies.should eq({0 => 0.4, 1 => 0.3, 2 => 0.2, 3 => 0.1})
end
end

4
spec/math/median.cr

@ -1,6 +1,6 @@
describe Math::Median do
it "test trivia" do
arr = ([]of Int32)
arr = ([] of Int32)
arr.median.should eq 0.0
end
@ -10,7 +10,7 @@ describe Math::Median do
[1, 2, 5].median.should eq 2.0
[2, 5, 1].median.should eq 2.0
[4, 1, 1, 1, 2].median.should eq 1.0
end
end

1
spec/math/quartile.cr

@ -79,6 +79,5 @@ module Math::Quartile
arr.upper_fence(3).should eq 47.5
arr.upper_outliers(3).should eq [1337]
end
end

2
src/lib/math/frequency.cr

@ -7,7 +7,7 @@ module Math::Frequency(T)
def all_frequencies : Hash(T, Float64)
values = to_set
frequencies = Hash(T, Float64).new(0.0f64, values.size)
each { |value| frequencies[value] += 1 }
each { |value| frequencies[value] += 1 }
frequencies.each { |k, _| frequencies[k] = frequencies[k] / size }
frequencies
end

2
src/lib/math/median.cr

@ -3,7 +3,7 @@ module Math::Median
return 0.0_f64 if empty?
sorted = sort
size = size()
return sorted[(size - 1) / 2].to_f64 if size.odd?
return sorted[(size - 1) / 2].to_f64 if size.odd?
(sorted[(size / 2) - 1] + sorted[size / 2]) / 2.0
end
end

2
src/lib/math/quartile.cr

@ -1,5 +1,5 @@
# There are several methods for computing the quartiles of an array.
#
#
# This library utilizes the method proposed by John Tukey
# https://en.wikipedia.org/wiki/Quartile#Method_2
#

Loading…
Cancel
Save