Skip to content

Commit 3bcd63e

Browse files
committed
Implement GPA score
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
1 parent 733dd4f commit 3bcd63e

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

lib/skunk/cli/grade_point_average.rb

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
module Skunk
4+
module Cli
5+
class GradePointAverage
6+
def initialize(skunk_score)
7+
@skunk_score = skunk_score
8+
end
9+
10+
def score
11+
case @skunk_score
12+
when (0..64)
13+
"A+"
14+
when (65..66)
15+
"A"
16+
when (67..69)
17+
"A-"
18+
when (70..72)
19+
"B+"
20+
when (73..76)
21+
"B"
22+
when (77..79)
23+
"B-"
24+
when (80..82)
25+
"C+"
26+
when (83..86)
27+
"C"
28+
when (87..89)
29+
"C-"
30+
when (90..92)
31+
"D+"
32+
when (93..96)
33+
"D"
34+
when (93..Float::INFINITY)
35+
"E"
36+
end
37+
end
38+
end
39+
end
40+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# frozen_string_literal: true
2+
3+
=begin
4+
|Letter Grade | Percent Grade | Scale |
5+
|:------------|:-------------:|------:|
6+
| A+ | Below 65 | 4.0 |
7+
| A | 65-66 | 4.0 |
8+
| A- | 67-69 | 3.7 |
9+
| B+ | 70-72 | 3.3 |
10+
| B | 73-76 | 3.0 |
11+
| B- | 77-79 | 2.7 |
12+
| C+ | 80-82 | 2.3 |
13+
| C | 83-86 | 2.0 |
14+
| C- | 87-89 | 1.7 |
15+
| D+ | 90-92 | 1.3 |
16+
| D | 93-96 | 1.0 |
17+
| E/F | 97-100 | 0.0 |
18+
=end
19+
20+
require "test_helper"
21+
22+
require "skunk/cli/grade_point_average"
23+
24+
describe Skunk::Cli::GradePointAverage do
25+
subject { Skunk::Cli::GradePointAverage }
26+
27+
describe "#score" do
28+
context "with A score" do
29+
it { expect(subject.new(0).score).must_equal "A+" }
30+
it { expect(subject.new(65).score).must_equal "A" }
31+
it { expect(subject.new(66).score).must_equal "A" }
32+
it { expect(subject.new(67).score).must_equal "A-" }
33+
it { expect(subject.new(69).score).must_equal "A-" }
34+
end
35+
36+
context "with B score" do
37+
it { expect(subject.new(70).score).must_equal "B+" }
38+
it { expect(subject.new(72).score).must_equal "B+" }
39+
it { expect(subject.new(73).score).must_equal "B" }
40+
it { expect(subject.new(76).score).must_equal "B" }
41+
it { expect(subject.new(77).score).must_equal "B-" }
42+
it { expect(subject.new(79).score).must_equal "B-" }
43+
end
44+
45+
context "with C score" do
46+
it { expect(subject.new(80).score).must_equal "C+" }
47+
it { expect(subject.new(82).score).must_equal "C+" }
48+
it { expect(subject.new(83).score).must_equal "C" }
49+
it { expect(subject.new(86).score).must_equal "C" }
50+
it { expect(subject.new(87).score).must_equal "C-" }
51+
it { expect(subject.new(89).score).must_equal "C-" }
52+
end
53+
54+
context "with D score" do
55+
it { expect(subject.new(90).score).must_equal "D+" }
56+
it { expect(subject.new(92).score).must_equal "D+" }
57+
it { expect(subject.new(93).score).must_equal "D" }
58+
it { expect(subject.new(96).score).must_equal "D" }
59+
end
60+
61+
context "with E score" do
62+
it { expect(subject.new(97).score).must_equal "E" }
63+
it { expect(subject.new(1000).score).must_equal "E" }
64+
it { expect(subject.new(10000).score).must_equal "E" }
65+
end
66+
end
67+
end

0 commit comments

Comments
 (0)