a gleam implementation of a CS assignment originally written in cpp

feat: add more tests

Changed files
+99 -7
test
+99 -7
test/bible_search_test.gleam
···
import bible_search
import gleeunit
+
import gleeunit/should
pub fn main() -> Nil {
gleeunit.main()
···
// gleeunit test functions end in `_test`
pub fn parse_reference_test() {
let ref = bible_search.parse_reference("FIRST KINGS 10 10")
+
should.be_ok(ref)
+
let expected_ref =
Ok(bible_search.Reference(book: "FIRST KINGS", chapter: 10, verse: 10))
-
assert Ok(ref) == Ok(expected_ref)
+
should.be_true(ref == expected_ref)
}
pub fn parse_reference_single_word_book_test() {
let ref = bible_search.parse_reference("GENESIS 1 1")
+
should.be_ok(ref)
+
let expected_ref =
Ok(bible_search.Reference(book: "GENESIS", chapter: 1, verse: 1))
-
assert Ok(ref) == Ok(expected_ref)
+
should.be_true(ref == expected_ref)
}
pub fn parse_reference_invalid_chapter_test() {
let ref = bible_search.parse_reference("GENESIS abc 1")
+
should.be_error(ref)
+
let expected_error = Error("Invalid chapter: abc")
-
assert ref == expected_error
+
should.be_true(ref == expected_error)
}
pub fn parse_reference_invalid_verse_test() {
let ref = bible_search.parse_reference("GENESIS 1 xyz")
+
should.be_error(ref)
let expected_error = Error("Invalid verse: xyz")
-
assert ref == expected_error
+
should.be_true(ref == expected_error)
}
pub fn parse_reference_too_few_parts_test() {
let ref = bible_search.parse_reference("GENESIS 1")
+
should.be_error(ref)
let expected_error = Error("invalid parse")
-
assert ref == expected_error
+
should.be_true(ref == expected_error)
}
pub fn parse_reference_too_many_parts_test() {
let ref = bible_search.parse_reference("SONG OF SOLOMON 1 1")
+
should.be_error(ref)
let expected_error = Error("invalid parse")
-
assert ref == expected_error
+
should.be_true(ref == expected_error)
}
pub fn parse_reference_lowercase_book_test() {
let ref = bible_search.parse_reference("genesis 1 1")
+
should.be_ok(ref)
+
let expected_ref =
Ok(bible_search.Reference(book: "GENESIS", chapter: 1, verse: 1))
-
assert Ok(ref) == Ok(expected_ref)
+
should.be_true(ref == expected_ref)
+
}
+
+
pub fn bible_scan_found_verse_test() {
+
let bible =
+
"THE BOOK OF GENESIS
+
+
CHAPTER 1
+
+
1 In the beginning God created the heaven and the earth.
+
2 And the earth was without form, and void; and darkness was upon the face of the deep."
+
+
let ref = bible_search.Reference(book: "GENESIS", chapter: 1, verse: 1)
+
let result = bible_search.bible_scan(reference: ref, bible: bible)
+
+
should.be_true(
+
result.verse == Ok("In the beginning God created the heaven and the earth."),
+
)
+
}
+
+
pub fn bible_scan_verse_not_found_test() {
+
let bible =
+
"THE BOOK OF GENESIS
+
+
CHAPTER 1
+
+
1 In the beginning God created the heaven and the earth."
+
+
let ref = bible_search.Reference(book: "GENESIS", chapter: 1, verse: 99)
+
let result = bible_search.bible_scan(reference: ref, bible: bible)
+
+
should.be_true(result.verse == Error("Verse not found"))
+
}
+
+
pub fn bible_scan_book_not_found_test() {
+
let bible =
+
"THE BOOK OF GENESIS
+
+
CHAPTER 1
+
+
1 In the beginning God created the heaven and the earth."
+
+
let ref = bible_search.Reference(book: "EXODUS", chapter: 1, verse: 1)
+
let result = bible_search.bible_scan(reference: ref, bible: bible)
+
+
should.be_true(result.verse == Error("Verse not found"))
+
}
+
+
pub fn bible_scan_chapter_not_found_test() {
+
let bible =
+
"THE BOOK OF GENESIS
+
+
CHAPTER 1
+
+
1 In the beginning God created the heaven and the earth."
+
+
let ref = bible_search.Reference(book: "GENESIS", chapter: 99, verse: 1)
+
let result = bible_search.bible_scan(reference: ref, bible: bible)
+
+
should.be_true(result.verse == Error("Verse not found"))
+
}
+
+
pub fn bible_scan_multiple_verses_test() {
+
let bible =
+
"THE BOOK OF GENESIS
+
+
CHAPTER 1
+
+
1 In the beginning God created the heaven and the earth.
+
2 And the earth was without form, and void; and darkness was upon the face of the deep.
+
3 And God said, Let there be light: and there was light."
+
+
let ref = bible_search.Reference(book: "GENESIS", chapter: 1, verse: 2)
+
let result = bible_search.bible_scan(reference: ref, bible: bible)
+
+
should.be_true(
+
result.verse
+
== Ok(
+
"And the earth was without form, and void; and darkness was upon the face of the deep.",
+
),
+
)
}