-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for the recursive power function
- Loading branch information
Showing
3 changed files
with
70 additions
and
25 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,50 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Author: Nelson Brochado | ||
Created: 18/01/2017 | ||
""" | ||
|
||
import unittest | ||
from random import randint | ||
|
||
from ands.algorithms.recursion.power import power | ||
|
||
|
||
class TestRecursivePower(unittest.TestCase): | ||
# Testing raising to power of 0. | ||
|
||
def test_base_0_power_0(self): | ||
self.assertEqual(power(0, 0), 1) | ||
|
||
def test_base_minus_1_power_0(self): | ||
self.assertEqual(power(-1, 0), 1) | ||
|
||
def test_base_1_power_0(self): | ||
self.assertEqual(power(1, 0), 1) | ||
|
||
def test_base_random_base_power_0(self): | ||
self.assertEqual(power(randint(2, 100), 0), 1) | ||
self.assertEqual(power(randint(-100, -2), 0), 1) | ||
|
||
def test_base_0_power_1(self): | ||
self.assertEqual(power(0, 1), 0) | ||
|
||
def test_base_1_power_1(self): | ||
self.assertEqual(power(1, 1), 1) | ||
|
||
def test_base_minus_1_power_1(self): | ||
self.assertEqual(power(-1, 1), -1) | ||
|
||
def test_random_base_power_1(self): | ||
a = randint(2, 100) | ||
b = randint(-100, -2) | ||
self.assertEqual(power(a, 1), a) | ||
self.assertEqual(power(b, 1), b) | ||
|
||
def test_random_base_random_positive_power(self): | ||
b = randint(-100, 100) | ||
p = randint(2, 100) | ||
self.assertEqual(power(b, p), b ** p) |