#!/usr/bin/env python # -*- coding: utf-8 -*- """ Napisz funkcję euclidean_distance obliczającą odległość między dwoma punktami przestrzeni trójwymiarowej. Punkty są dane jako trzyelementowe listy liczb zmiennoprzecinkowych. np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. """ def euclidean_distance(x, y): def test_special_cases(self): """Testy przypadków szczególnych.""" self.assertAlmostEqual( euclidean_distance((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), 0.0) self.assertAlmostEqual( euclidean_distance((3.6, -1.7, 0.3), (3.6, -1.7, 0.3)), 0.0) self.assertAlmostEqual( euclidean_distance((2.3, 4.3, -7.5), (2.3, 8.5, -7.5)), 4.2) def test_regular_cases(self): """Testy dla zwykłych przypadków""" self.assertAlmostEqual( euclidean_distance((0.0, 0.0, 0.0), (0.0, 4.0, 3.0)), 5.0) self.assertAlmostEqual( euclidean_distance((2.4, -5.1, 3.0), (5.3, 2.1, 10.0)), 10.4523, 3) def tests(f): inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]] outputs = [4.2] for input, output in zip(inputs, outputs): if f(*input) != output: return "ERROR: {}!={}".format(f(*input), output) break return "TESTS PASSED" if __name__ == "__main__": print(tests(euclidean_distance))