Skip to content

Commit

Permalink
Implement GPA score
Browse files Browse the repository at this point in the history
I'm trying to follow the [GPA (grade point average)](https://bigfuture.collegeboard.org/plan-for-college/college-basics/how-to-convert-gpa-4.0-scale)
but the example there used the 4.0 scale, and I'm not pretty sure if we
want that.

Closes #95
  • Loading branch information
JuanVqz committed Sep 21, 2022
1 parent 733dd4f commit 3bcd63e
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/skunk/cli/grade_point_average.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

module Skunk
module Cli
class GradePointAverage
def initialize(skunk_score)
@skunk_score = skunk_score
end

def score
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
67 changes: 67 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,67 @@
# frozen_string_literal: true

=begin
|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 |
=end

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(10000).score).must_equal "E" }
end
end
end

0 comments on commit 3bcd63e

Please sign in to comment.