# Path: mpinterfaces/transformations.py
# def get_r_list(area1, area2, max_area, tol=0.02):
#     """
#     Returns a list of r1 and r2 values that satisfies:
#     r1/r2 = area2/area1 with the constraints:
#     r1 <= Area_max/area1 and r2 <= Area_max/area2
#     r1 and r2 corresponds to the supercell sizes of the 2 interfaces
#     that align them
#     """
#     r_list = []
#     rmax1 = int(max_area / area1)
#     rmax2 = int(max_area / area2)
#     print('rmax1, rmax2: {0}, {1}\n'.format(rmax1, rmax2))
#     for r1 in range(1, rmax1 + 1):
#         for r2 in range(1, rmax2 + 1):
#             if abs(float(r1) * area1 - float(r2) * area2) / max_area <= tol:
#                 r_list.append([r1, r2])
#     return r_list


import unittest
import sys
from mpinterfaces.transformations import get_r_list
from io import StringIO
__maintainer__ = "Joshua J. Gabriel"
__email__ = "joshgabriel92@gmail.com"
__status__ = "Production"
__date__ = "March 3, 2017"


class TestGetRList(unittest.TestCase):

    def setUp(self):
        self.old_stdout = sys.stdout
        sys.stdout = self.mystdout = StringIO()

    def tearDown(self):
        sys.stdout = self.old_stdout

    # Expect rmax is the floor of the max divided by its
    # correponding area argument
    def test_half(self):
        self.assertEqual([[1, 1]], get_r_list(1, 0.98, 2))
        self.assertEqual('rmax1, rmax2: 2, 2\n\n', self.mystdout.getvalue())

    def test_half_decimal(self):
        self.assertEqual([[1, 1], [2, 2]], get_r_list(1.5, 1.5, 3))
        self.assertEqual('rmax1, rmax2: 2, 2\n\n', self.mystdout.getvalue())

    def test_half_error_margin(self):
        self.assertEqual([], get_r_list(1.5, 1.6, 3))
        self.assertEqual('rmax1, rmax2: 2, 1\n\n', self.mystdout.getvalue())

    def test_altered_error_margin(self):

# Path: mpinterfaces/transformations.py
# def get_r_list(area1, area2, max_area, tol=0.02):
#     """
#     Returns a list of r1 and r2 values that satisfies:
#     r1/r2 = area2/area1 with the constraints:
#     r1 <= Area_max/area1 and r2 <= Area_max/area2
#     r1 and r2 corresponds to the supercell sizes of the 2 interfaces
#     that align them
#     """
#     r_list = []
#     rmax1 = int(max_area / area1)
#     rmax2 = int(max_area / area2)
#     print('rmax1, rmax2: {0}, {1}\n'.format(rmax1, rmax2))
#     for r1 in range(1, rmax1 + 1):
#         for r2 in range(1, rmax2 + 1):
#             if abs(float(r1) * area1 - float(r2) * area2) / max_area <= tol:
#                 r_list.append([r1, r2])
#     return r_list


# Path: mpinterfaces/tests/test_get_r_list.py
import unittest
import sys
from mpinterfaces.transformations import get_r_list
from io import StringIO

__maintainer__ = "Joshua J. Gabriel"
__email__ = "joshgabriel92@gmail.com"
__status__ = "Production"
__date__ = "March 3, 2017"


class TestGetRList(unittest.TestCase):

    def setUp(self):
        self.old_stdout = sys.stdout
        sys.stdout = self.mystdout = StringIO()

    def tearDown(self):
        sys.stdout = self.old_stdout

    # Expect rmax is the floor of the max divided by its
    # correponding area argument
    def test_half(self):
        self.assertEqual([[1, 1]], get_r_list(1, 0.98, 2))
        self.assertEqual('rmax1, rmax2: 2, 2\n\n', self.mystdout.getvalue())

    def test_half_decimal(self):
        self.assertEqual([[1, 1], [2, 2]], get_r_list(1.5, 1.5, 3))
        self.assertEqual('rmax1, rmax2: 2, 2\n\n', self.mystdout.getvalue())

    def test_half_error_margin(self):
        self.assertEqual([], get_r_list(1.5, 1.6, 3))
        self.assertEqual('rmax1, rmax2: 2, 1\n\n', self.mystdout.getvalue())

    def test_altered_error_margin(self):

        self.assertEqual([[1, 1]], get_r_list(1.5, 1.6, 3, 0.04))