Skip to content

Commit

Permalink
Rename functions to describe their purpose better.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryouze committed Oct 24, 2024
1 parent e130287 commit 96f2fd2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class UI final {
{
// Lambda functions for setup
auto setup_new_question = [&]() {
const auto optional_entry = this->vocabulary_.get_random_entry();
const auto optional_entry = this->vocabulary_.get_random_enabled_entry();
if (!optional_entry.has_value()) {
this->question_text_.setString("X");
this->question_text_.setCharacterSize(72); // Increase font size for the 'X'
Expand All @@ -191,7 +191,7 @@ class UI final {
this->is_hangul_ = core::rng::RNG::get_random_bool();

// Get unique options
const auto options = this->vocabulary_.get_question_options(this->correct_entry_);
const auto options = this->vocabulary_.generate_enabled_question_options(this->correct_entry_);

// Find the index of the correct answer after shuffling
for (std::size_t idx = 0; idx < 4; ++idx) {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/vocabulary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace modules::vocabulary {
Vocabulary::Vocabulary()
// Transliteration reference: http://letslearnhangul.com/
// Note: The number of entries in each category must be greater than 3 (i.e., 4, 5, 6, 7, 8, 9, etc.).
// If 3 or fewer entries are present in a category, the get_question_options will throw an exception and the program will crash.
// If 3 or fewer entries are present in a category, the generate_enabled_question_options will throw an exception and the program will crash.
// The automated tests count the number of entries in each category to ensure this requirement is met.
: entries_{
// Basic vowels
Expand Down Expand Up @@ -72,7 +72,7 @@ Vocabulary::Vocabulary()
{
}

std::optional<Entry> Vocabulary::get_random_entry()
std::optional<Entry> Vocabulary::get_random_enabled_entry()
{
// Collect enabled entries
std::vector<Entry> enabled_entries;
Expand All @@ -90,8 +90,8 @@ std::optional<Entry> Vocabulary::get_random_entry()
return enabled_entries.at(index);
}

std::vector<Entry> Vocabulary::get_question_options(const Entry &correct_entry,
const std::size_t num_options)
std::vector<Entry> Vocabulary::generate_enabled_question_options(const Entry &correct_entry,
const std::size_t num_options)
{
std::vector<Entry> options = {correct_entry};

Expand Down
6 changes: 3 additions & 3 deletions src/modules/vocabulary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Vocabulary final {
*
* @return Entry object where the category is enabled, or std::nullopt if no categories are enabled.
*/
[[nodiscard]] std::optional<Entry> get_random_entry();
[[nodiscard]] std::optional<Entry> get_random_enabled_entry();

/**
* @brief Get a set of unique options for a question.
Expand All @@ -77,8 +77,8 @@ class Vocabulary final {
*
* @throws std::runtime_error if the size of the vector is less than "num_options" because there are not enough unique entries.
*/
[[nodiscard]] std::vector<Entry> get_question_options(const Entry &correct_entry,
const std::size_t num_options = 4);
[[nodiscard]] std::vector<Entry> generate_enabled_question_options(const Entry &correct_entry,
const std::size_t num_options = 4);

/**
* @brief Enable or disable a category in the vocabulary.
Expand Down

0 comments on commit 96f2fd2

Please sign in to comment.