'''
Test fast exponentiation by squaring
'''

import pytest

from src.fpow import fpow0, fpow1, fpow2


@pytest.mark.parametrize('fpow', [fpow0, fpow1, fpow2])
@pytest.mark.parametrize('x', list(range(-100, 100)))
# 997 is a prime number. This ensures different choices for `n`.
@pytest.mark.parametrize('n', list(range(10)) + list(range(10, 10000, 997)))
def test_fpow_nonzero(fpow, x, n):
    if x == 0:
        assert True, 'a separate unit test will deal with x == 0'

        return

    assert fpow(x, n) == pow(x, n), '{} failed for {}^{}'.format(
        fpow.__name__, x, n
    )


@pytest.mark.parametrize('fpow', [fpow0, fpow1, fpow2])
@pytest.mark.parametrize('x', list(range(-10, 10)))
def test_fpow_nzero(fpow, x):
    assert fpow(x, 0) == 1, '{} failed for {}^{}'.format(fpow.__name__, x, 0)


@pytest.mark.parametrize('fpow', [fpow0, fpow1, fpow2])
@pytest.mark.parametrize('n', list(range(-100, 0)))
def test_fpow_xzero_nneg_throws(fpow, n):
    '''Make sure that for x == 0 and n < 0 an exception is throws'''

    with pytest.raises(ZeroDivisionError):
        fpow(0, n)

@@ -313,16 +313,21 @@
 t(range(
+-10, 
 10)) + l
@@ -490,32 +490,36 @@
 urn%0A%0A    assert 
+abs(
 fpow(x, n) == po
@@ -513,18 +513,17 @@
 w(x, n) 
-==
+-
  pow(x, 
@@ -524,16 +524,24 @@
 ow(x, n)
+) %3C 1e-9
 , '%7B%7D fa

Test some integral, but negative values for n