Skip to content
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

Implement GPA score #100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions lib/skunk/cli/grade_point_average.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

module Skunk
module Cli
# Knows how to calculate GPA score
class GradePointAverage
def initialize(skunk_score)
@skunk_score = skunk_score
end

def score # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
case @skunk_score
when (0..64)
"A+"
when (65..66)
"A"
when (67..69)
"A-"
when (70..72)
"B+"
when (73..76)
"B"
when (77..79)
"B-"
when (80..82)
"C+"
when (83..86)
"C"
when (87..89)
"C-"
when (90..92)
"D+"
when (93..96)
"D"
when (93..Float::INFINITY)
"E"
end
end
end
end
end
65 changes: 65 additions & 0 deletions test/lib/skunk/cli/grade_point_average_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true

# |Letter Grade | Percent Grade | Scale |
# |:------------|:-------------:|------:|
# | A+ | Below 65 | 4.0 |
# | A | 65-66 | 4.0 |
# | A- | 67-69 | 3.7 |
# | B+ | 70-72 | 3.3 |
# | B | 73-76 | 3.0 |
# | B- | 77-79 | 2.7 |
# | C+ | 80-82 | 2.3 |
# | C | 83-86 | 2.0 |
# | C- | 87-89 | 1.7 |
# | D+ | 90-92 | 1.3 |
# | D | 93-96 | 1.0 |
# | E/F | 97-100 | 0.0 |

require "test_helper"

require "skunk/cli/grade_point_average"

describe Skunk::Cli::GradePointAverage do
subject { Skunk::Cli::GradePointAverage }

describe "#score" do
context "with A score" do
it { expect(subject.new(0).score).must_equal "A+" }
it { expect(subject.new(65).score).must_equal "A" }
it { expect(subject.new(66).score).must_equal "A" }
it { expect(subject.new(67).score).must_equal "A-" }
it { expect(subject.new(69).score).must_equal "A-" }
end

context "with B score" do
it { expect(subject.new(70).score).must_equal "B+" }
it { expect(subject.new(72).score).must_equal "B+" }
it { expect(subject.new(73).score).must_equal "B" }
it { expect(subject.new(76).score).must_equal "B" }
it { expect(subject.new(77).score).must_equal "B-" }
it { expect(subject.new(79).score).must_equal "B-" }
end

context "with C score" do
it { expect(subject.new(80).score).must_equal "C+" }
it { expect(subject.new(82).score).must_equal "C+" }
it { expect(subject.new(83).score).must_equal "C" }
it { expect(subject.new(86).score).must_equal "C" }
it { expect(subject.new(87).score).must_equal "C-" }
it { expect(subject.new(89).score).must_equal "C-" }
end

context "with D score" do
it { expect(subject.new(90).score).must_equal "D+" }
it { expect(subject.new(92).score).must_equal "D+" }
it { expect(subject.new(93).score).must_equal "D" }
it { expect(subject.new(96).score).must_equal "D" }
end

context "with E score" do
it { expect(subject.new(97).score).must_equal "E" }
it { expect(subject.new(1000).score).must_equal "E" }
it { expect(subject.new(10_000).score).must_equal "E" }
end
end
end