Ива качи първо решение на 25.11.2018 22:20 (преди почти 5 години)
Разумно решение като цяло, но си сбъркала формулата от линка, което ти е коствало трите теста. Погледни и warning-ите за съвет какво друго да промениш в кода си като стил.
Compiling solution v0.1.0 (/tmp/d20190123-22631-xj3lv2/solution) warning: unnecessary parentheses around `if` condition --> src/lib.rs:159:12 | 159 | if (vector_length(n) == 0.0) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses | = note: #[warn(unused_parens)] on by default warning: unnecessary parentheses around `if` condition --> src/lib.rs:159:12 | 159 | if (vector_length(n) == 0.0) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses | = note: #[warn(unused_parens)] on by default Finished dev [unoptimized + debuginfo] target(s) in 5.20s Running target/debug/deps/solution-2e785d603b538f71 running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out Running target/debug/deps/solution_test-29808948fb50ed3a running 15 tests test solution_test::test_equailty_symmetry ... ok test solution_test::test_equality_basic ... ok test solution_test::test_equality_floating ... ok test solution_test::test_line_constructors ... ok test solution_test::test_line_equality_by_points ... ok test solution_test::test_line_equality_by_points_and_vectors ... FAILED test solution_test::test_line_equality_by_vectors ... FAILED test solution_test::test_line_validity ... ok test solution_test::test_number_by_vector ... ok test solution_test::test_number_vector_multiplication_with_precision ... ok test solution_test::test_point_distance ... FAILED test solution_test::test_points_minus_points ... ok test solution_test::test_points_plus_vectors ... ok test solution_test::test_vector_by_vector ... ok test solution_test::test_vector_by_vector_cross ... ok failures: ---- solution_test::test_line_equality_by_points_and_vectors stdout ---- 0 0 0 0 0 0.6324555320336759 thread 'solution_test::test_line_equality_by_points_and_vectors' panicked at 'assertion failed: `(left == right)` left: `Some(Line { x: Point { x: 0.0, y: 0.0, z: 0.0 }, y: Point { x: 0.3, y: -0.1, z: 0.25 } })`, right: `Some(Line { x: Point { x: 0.0, y: 0.0, z: 0.0 }, y: Point { x: -0.6, y: 0.2, z: -0.5 } })`', tests/solution_test.rs:245:5 note: Run with `RUST_BACKTRACE=1` for a backtrace. ---- solution_test::test_line_equality_by_vectors stdout ---- 0 0 0 0.1825300804627884 thread 'solution_test::test_line_equality_by_vectors' panicked at 'assertion failed: `(left == right)` left: `Some(Line { x: Point { x: 0.0, y: 0.4, z: 0.0 }, y: Point { x: 0.1, y: 0.2, z: 0.5 } })`, right: `Some(Line { x: Point { x: 0.0, y: 0.4, z: 0.0 }, y: Point { x: 0.03333333333333333, y: 0.33333333333333337, z: 0.16666666666666666 } })`', tests/solution_test.rs:227:5 ---- solution_test::test_point_distance stdout ---- thread 'solution_test::test_point_distance' panicked at 'assertion failed: (line.distance(p1) - 2.0f64.sqrt() / 2.0).abs() < EPS * 1000.0', tests/solution_test.rs:183:5 failures: solution_test::test_line_equality_by_points_and_vectors solution_test::test_line_equality_by_vectors solution_test::test_point_distance test result: FAILED. 12 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out error: test failed, to rerun pass '--test solution_test'
Разумно решение като цяло, но си сбъркала формулата от линка, което ти е коствало трите теста. Погледни и warning-ите за съвет какво друго да промениш в кода си като стил.
Ако x е
-1.0
, а y е1.0
, това са две доста различни числа, но тази функция ще върне истина. Формулата трябва да е(x - y).abs() < std::f64::EPSILON
.Вектора n предполагам, че е трябвало да бъде вектора-посока на правата. Но начина да го получиш от две точки, лежащи върху нея е просто
self.y - self.x
. Илиself.x - self.y
. Тази една промяна би минала всички тестове.