From 4f646deb7364ac074a326aa4f699899f34b1e05c Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Thu, 20 Jun 2024 13:54:39 -0400 Subject: [PATCH] Add unit test for Author, and new testcase for Book --- test/author_test.rb | 36 ++++++++++++++++++++++++++++++++++++ test/book_test.rb | 13 +++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/author_test.rb diff --git a/test/author_test.rb b/test/author_test.rb new file mode 100644 index 0000000..088d4d0 --- /dev/null +++ b/test/author_test.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "test_helper" +require "author" + +class AuthorTest < Minitest::Test + def test_that_initialization_values_are_reflected_in_the_created_object + grouping = "Daniel Defoe" + reading_order = "Daniel Defoe" + sort_order = "Defoe, Daniel" + + author = Author.new(grouping, reading_order, sort_order) + + assert_equal grouping, author.grouping + assert_equal reading_order, author.reading_order + assert_equal sort_order, author.sort_order + end + + def test_that_sort_order_is_auto_inferred + grouping = "DanielDefoe" + reading_order = "Daniel Defoe" + + author = Author.new(grouping, reading_order, nil) + + assert_equal "Defoe, Daniel", author.sort_order + end + + def test_inspect + author = Author.new("DanielDefoe", "Daniel Defoe", "Defoe, Daniel") + + expected = '(Author: grouping="DanielDefoe" reading_order="Daniel Defoe" sort_order="Defoe, Daniel")' + + assert_equal expected, author.inspect + assert_equal expected, author.to_s + end +end diff --git a/test/book_test.rb b/test/book_test.rb index de32278..90c918a 100644 --- a/test/book_test.rb +++ b/test/book_test.rb @@ -15,4 +15,17 @@ class BookTest < Minitest::Test assert_equal false, Book.can_handle?("sample.#{extension}") end end + + def test_grouping_for_title + data = { + "A Study in Scarlet" => "A_Study_in_Scarlet", + "That'll be the Day" => "That-ll_be_the_Day", + "Banzai!" => "Banzai-", + "#tweet_cute" => "-tweet_cute", + } + + data.each do |input, expected| + assert_equal expected, Book.grouping_for_title(input) + end + end end -- 2.39.2