a gleam implementation of a CS assignment originally written in cpp
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add more tests

+99 -7
+99 -7
test/bible_search_test.gleam
··· 1 1 import bible_search 2 2 import gleeunit 3 + import gleeunit/should 3 4 4 5 pub fn main() -> Nil { 5 6 gleeunit.main() ··· 8 9 // gleeunit test functions end in `_test` 9 10 pub fn parse_reference_test() { 10 11 let ref = bible_search.parse_reference("FIRST KINGS 10 10") 12 + should.be_ok(ref) 13 + 11 14 let expected_ref = 12 15 Ok(bible_search.Reference(book: "FIRST KINGS", chapter: 10, verse: 10)) 13 16 14 - assert Ok(ref) == Ok(expected_ref) 17 + should.be_true(ref == expected_ref) 15 18 } 16 19 17 20 pub fn parse_reference_single_word_book_test() { 18 21 let ref = bible_search.parse_reference("GENESIS 1 1") 22 + should.be_ok(ref) 23 + 19 24 let expected_ref = 20 25 Ok(bible_search.Reference(book: "GENESIS", chapter: 1, verse: 1)) 21 26 22 - assert Ok(ref) == Ok(expected_ref) 27 + should.be_true(ref == expected_ref) 23 28 } 24 29 25 30 pub fn parse_reference_invalid_chapter_test() { 26 31 let ref = bible_search.parse_reference("GENESIS abc 1") 32 + should.be_error(ref) 33 + 27 34 let expected_error = Error("Invalid chapter: abc") 28 35 29 - assert ref == expected_error 36 + should.be_true(ref == expected_error) 30 37 } 31 38 32 39 pub fn parse_reference_invalid_verse_test() { 33 40 let ref = bible_search.parse_reference("GENESIS 1 xyz") 41 + should.be_error(ref) 34 42 let expected_error = Error("Invalid verse: xyz") 35 43 36 - assert ref == expected_error 44 + should.be_true(ref == expected_error) 37 45 } 38 46 39 47 pub fn parse_reference_too_few_parts_test() { 40 48 let ref = bible_search.parse_reference("GENESIS 1") 49 + should.be_error(ref) 41 50 let expected_error = Error("invalid parse") 42 51 43 - assert ref == expected_error 52 + should.be_true(ref == expected_error) 44 53 } 45 54 46 55 pub fn parse_reference_too_many_parts_test() { 47 56 let ref = bible_search.parse_reference("SONG OF SOLOMON 1 1") 57 + should.be_error(ref) 48 58 let expected_error = Error("invalid parse") 49 59 50 - assert ref == expected_error 60 + should.be_true(ref == expected_error) 51 61 } 52 62 53 63 pub fn parse_reference_lowercase_book_test() { 54 64 let ref = bible_search.parse_reference("genesis 1 1") 65 + should.be_ok(ref) 66 + 55 67 let expected_ref = 56 68 Ok(bible_search.Reference(book: "GENESIS", chapter: 1, verse: 1)) 57 69 58 - assert Ok(ref) == Ok(expected_ref) 70 + should.be_true(ref == expected_ref) 71 + } 72 + 73 + pub fn bible_scan_found_verse_test() { 74 + let bible = 75 + "THE BOOK OF GENESIS 76 + 77 + CHAPTER 1 78 + 79 + 1 In the beginning God created the heaven and the earth. 80 + 2 And the earth was without form, and void; and darkness was upon the face of the deep." 81 + 82 + let ref = bible_search.Reference(book: "GENESIS", chapter: 1, verse: 1) 83 + let result = bible_search.bible_scan(reference: ref, bible: bible) 84 + 85 + should.be_true( 86 + result.verse == Ok("In the beginning God created the heaven and the earth."), 87 + ) 88 + } 89 + 90 + pub fn bible_scan_verse_not_found_test() { 91 + let bible = 92 + "THE BOOK OF GENESIS 93 + 94 + CHAPTER 1 95 + 96 + 1 In the beginning God created the heaven and the earth." 97 + 98 + let ref = bible_search.Reference(book: "GENESIS", chapter: 1, verse: 99) 99 + let result = bible_search.bible_scan(reference: ref, bible: bible) 100 + 101 + should.be_true(result.verse == Error("Verse not found")) 102 + } 103 + 104 + pub fn bible_scan_book_not_found_test() { 105 + let bible = 106 + "THE BOOK OF GENESIS 107 + 108 + CHAPTER 1 109 + 110 + 1 In the beginning God created the heaven and the earth." 111 + 112 + let ref = bible_search.Reference(book: "EXODUS", chapter: 1, verse: 1) 113 + let result = bible_search.bible_scan(reference: ref, bible: bible) 114 + 115 + should.be_true(result.verse == Error("Verse not found")) 116 + } 117 + 118 + pub fn bible_scan_chapter_not_found_test() { 119 + let bible = 120 + "THE BOOK OF GENESIS 121 + 122 + CHAPTER 1 123 + 124 + 1 In the beginning God created the heaven and the earth." 125 + 126 + let ref = bible_search.Reference(book: "GENESIS", chapter: 99, verse: 1) 127 + let result = bible_search.bible_scan(reference: ref, bible: bible) 128 + 129 + should.be_true(result.verse == Error("Verse not found")) 130 + } 131 + 132 + pub fn bible_scan_multiple_verses_test() { 133 + let bible = 134 + "THE BOOK OF GENESIS 135 + 136 + CHAPTER 1 137 + 138 + 1 In the beginning God created the heaven and the earth. 139 + 2 And the earth was without form, and void; and darkness was upon the face of the deep. 140 + 3 And God said, Let there be light: and there was light." 141 + 142 + let ref = bible_search.Reference(book: "GENESIS", chapter: 1, verse: 2) 143 + let result = bible_search.bible_scan(reference: ref, bible: bible) 144 + 145 + should.be_true( 146 + result.verse 147 + == Ok( 148 + "And the earth was without form, and void; and darkness was upon the face of the deep.", 149 + ), 150 + ) 59 151 }