]> jaekl.net Git - quanlib.git/commitdiff
Add unit test for Classification, and fix bug that that uncovered
authorChris Jaekl <chris@jaekl.net>
Fri, 21 Jun 2024 23:49:12 +0000 (19:49 -0400)
committerChris Jaekl <chris@jaekl.net>
Fri, 21 Jun 2024 23:49:12 +0000 (19:49 -0400)
app/classification.rb
test/classification_test.rb [new file with mode: 0644]

index 2061e46def695b6cadbd741eb305e3480f4629e9..1fb7e12f47df37e0acd7b4ed6387ea8a04870737 100644 (file)
@@ -29,31 +29,30 @@ class Classification
   def author
     @author
   end
-  def 
 
   def inspect
     data = []
  
     if nil != @ddc
-      data.push('Dewey=' + @ddc.to_s)
+      data.push('Dewey=' + @ddc.to_s.inspect)
     end
     if nil != @lcc
-      data.push('LCC=' + @lcc.to_s)
+      data.push('LCC=' + @lcc.to_s.inspect)
     end
     if nil != @author_grouping
-      data.push('author_grouping=' + @author_grouping.to_s)
+      data.push('author_grouping=' + @author_grouping.to_s.inspect)
     end
     if nil != @author
-      data.push('author=' + @author.to_s)
+      data.push('author=' + @author.to_s.inspect)
     end
     if nil != @title_grouping
-      data.push('title_grouping=' + @title_grouping.to_s)
+      data.push('title_grouping=' + @title_grouping.to_s.inspect)
     end
     if nil != @title
-      data.push('title=' + @title)
+      data.push('title=' + @title.inspect)
     end
 
-    return '(Classification:' + data.join(',') + ')'
+    return '(Classification: ' + data.join(', ') + ')'
   end
 
   def to_s
diff --git a/test/classification_test.rb b/test/classification_test.rb
new file mode 100644 (file)
index 0000000..fd11643
--- /dev/null
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require "test_helper"
+require "classification"
+
+class ClassificationTest < Minitest::Test
+  def test_inspect
+    ddc = "973.3/092 B"
+    lcc = "E302.6.F7"
+    author_grouping = "BenjaminFranklin"
+    author_sort = "Franklin, Benjamin"
+    title_grouping = "Autobiography_of_Benjamin_Franklin"
+    title = "Autobiography of Benjamin Franklin"
+    
+    classification = Classification.new(ddc, lcc, author_grouping, author_sort, title_grouping, title)
+
+    expected = '(Classification: Dewey="973.3/092 B", LCC="E302.6.F7", author_grouping="BenjaminFranklin", author="Franklin, Benjamin", title_grouping="Autobiography_of_Benjamin_Franklin", title="Autobiography of Benjamin Franklin")'
+    actual = classification.inspect
+
+    assert_equal expected, actual
+  end
+end