Skip to content

Commit

Permalink
Fix small bug where adjective corpus list was serialized with an empt…
Browse files Browse the repository at this point in the history
…y word.

This happened because there are no length-20 words in the adjectives list, so an empty array was being treated as an empty word.
  • Loading branch information
schmich committed Jun 22, 2021
1 parent ded3436 commit 82b2a37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion corpus/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

fixed_file = File.join(out_dir, File.basename(source, '.txt') + '-fixed.bin')
File.open(fixed_file, 'wb') do |w|
puts "Write #{fixed_file}."
width = words.keys.max
header.write(w)
words.values.flatten.each do |word|
Expand All @@ -45,7 +46,8 @@

packed_file = File.join(out_dir, File.basename(source, '.txt') + '.bin')
File.open(packed_file, 'wb') do |w|
puts "Write #{packed_file}."
header.write(w)
w.write(words.values.join("\0"))
w.write(words.values.flatten.join("\0"))
end
end
4 changes: 4 additions & 0 deletions tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def test_word_lists
refute(c.nouns.empty?)
refute(c.adverbs.empty?)
refute(c.verbs.empty?)
refute(c.adjectives.any?(&:empty?))
refute(c.nouns.any?(&:empty?))
refute(c.adverbs.any?(&:empty?))
refute(c.verbs.any?(&:empty?))
end

private
Expand Down

0 comments on commit 82b2a37

Please sign in to comment.