Решение на Wordle от Давид Петров
Резултати
- 19 точки от тестове
- 0 бонус точки
- 19 точки общо
- 14 успешни тест(а)
- 1 неуспешни тест(а)
Код
Лог от изпълнението
Compiling solution v0.1.0 (/tmp/d20230111-3772066-55xywx/solution) Finished test [unoptimized + debuginfo] target(s) in 0.86s Running tests/solution_test.rs (target/debug/deps/solution_test-0edbea2040daef01) running 15 tests test solution_test::test_game_display ... ok test solution_test::test_game_display_german ... ok test solution_test::test_game_display_cyrillic ... ok test solution_test::test_game_state_1 ... ok test solution_test::test_game_state_2 ... ok test solution_test::test_game_state_3 ... ok test solution_test::test_word_display ... ok test solution_test::test_word_display_bulgarian ... ok test solution_test::test_word_display_german ... ok test solution_test::test_word_not_in_alphabet_on_construction ... ok test solution_test::test_word_display_with_repetitions ... FAILED test solution_test::test_word_not_in_alphabet_on_construction_cyrrilic ... ok test solution_test::test_word_not_in_alphabet_on_guess ... ok test solution_test::test_word_not_in_alphabet_on_guess_cyrillic ... ok test solution_test::test_wrong_length ... ok failures: ---- solution_test::test_word_display_with_repetitions stdout ---- thread 'solution_test::test_word_display_with_repetitions' panicked at 'assertion failed: `(left == right)` left: `"(P)[O](O)(B)"`, right: `"(P)[O][O](B)"`', tests/solution_test.rs:68:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: solution_test::test_word_display_with_repetitions test result: FAILED. 14 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s error: test failed, to rerun pass `--test solution_test`
История (3 версии и 4 коментара)
Давид качи решение на 20.11.2022 00:23 (преди почти 3 години)
That's just a tip I found on stack overflow regarding the newline characters. Decided to leave it in, although that is regarded as obsolete in most cases.
Давид качи решение на 20.11.2022 22:49 (преди почти 3 години)
Any idea how we could shorten this (not that it's of utmost necessity, but just wondering...)? I stumlbed across a lot of rather nasty string literal requirements for the macros to work (predictably so) and, finally, couldn't even find a string interpolation alternative with dynamic patterns.
Added some crucial fixes regarding utf-8 peculiarities, plus a few more pickier tests in that regard.
От всичките игри с corner case-ове, накрая някак фундаментално грешната логика за търсене на символ така и не ми е направила впечатление след всичките тестови примери, които ми хрумнаха... щото кой да се замисли малко повече... :D Да спестя гледане за обратна връзка: като цяло винаги спирам търсенето до първо срещане на символа и дори и да има на търсения индекс някое следващо срещане, сравнявам с първия и го пиша PartialMatch... Голяма глупост :D
Реално искаме по-скоро нещо такова:
let match_char_at_position = |(index, character) : (usize, char)| {
let occurrences: Vec<usize> =
self.word.chars()
.enumerate()
.filter(|(_index, c)| *c == character)
.map(|p| p.0)
.collect();
let state =
if occurrences.contains(&index) {
LetterState::FullMatch
} else if !occurrences.is_empty() {
LetterState::PartialMatch
} else {
LetterState::NoMatch
};
Letter {character, state}
};
That's just a tip I found on stack overflow regarding the newline characters. Decided to leave it in, although that is regarded as obsolete in most cases.
Any idea how we could shorten this (not that it's of utmost necessity, but just wondering...)? I stumlbed across a lot of rather nasty string literal requirements for the macros to work (predictably so) and, finally, couldn't even find a string interpolation alternative with dynamic patterns.