forked from Jason2Brownlee/CleverAlgorithms
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a651b6
commit 4f32123
Showing
4 changed files
with
166 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import math | ||
|
||
""" | ||
Not in the original code listing. This factors out the common functions | ||
used in Chapter 2. | ||
""" | ||
|
||
def euc_2d(p1, p2): | ||
dx = p1[0] - p2[0] | ||
dy = p1[1] - p2[1] | ||
return math.sqrt((dx ** 2) + (dy ** 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import stochastic | ||
import unittest | ||
|
||
""" | ||
Tests for the base class of Chapter 2: Stochastic Algorithms | ||
""" | ||
|
||
class StochasticTests(unittest.TestCase): | ||
|
||
def test_euc_2d(self): | ||
self.assertEqual(0, stochastic.euc_2d([0, 0], [0, 0])) | ||
self.assertEqual(0, stochastic.euc_2d([1.1, 1.1], [1.1, 1.1])) | ||
self.assertEqual(1, stochastic.euc_2d([1, 1], [2, 2])) | ||
self.assertEqual(3, stochastic.euc_2d([-1, -1], [1, 1])) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |