"""
This file is part of Advent of Code 2019.

Coded by: <NAME> (<EMAIL>)
11 December 2019

NO COPYRIGHT
This work is dedicated to the public domain.  All rights have been
waived worldwide under copyright law, including all related and
neighboring rights, to the extent allowed by law.

You may copy, modify, distribute, and perform the work, even for
commercial purposes, all without asking permission.  See the
accompanying COPYRIGHT document.
"""

import unittest
from day1 import FuelCounterUpper


class TestFuelCounterUpper(unittest.TestCase):

    def test_add_module_types(self):
        """
        Checks for TypeError
        """
        f = FuelCounterUpper()
        with self.assertRaises(TypeError):
            # noinspection PyTypeChecker
            f.add_module('string')

    def test_add_module_values(self):
        """
        Checks for negative or excessively large values
        """
        f = FuelCounterUpper()
        with self.assertRaises(ValueError):
            f.add_module(-5)
        with self.assertRaises(ValueError):
            f.add_module(2**64)

    def test_set_attr(self):
        """
        Ensure we cannot overwrite the internal properties
        """
        f = FuelCounterUpper()
        with self.assertRaises(NotImplementedError):
            f.total_fuel = 1
        with self.assertRaises(NotImplementedError):
            f.total_mass = 1

    def test_del_attr(self):
        """
        Ensure we cannot delete the internal properties
        """
        f = FuelCounterUpper()
        with self.assertRaises(NotImplementedError):
            del f.total_fuel
        with self.assertRaises(NotImplementedError):
            del f.total_mass

    def test_given(self):
        """
        Runs the given test vectors from AoC:

        For a mass of 12, divide by 3 and round down to get 4, then subtract 2 to get 2.
        For a mass of 14, dividing by 3 and rounding down still yields 4, so the fuel required is also 2.
        For a mass of 1969, the fuel required is 654.
        For a mass of 100756, the fuel required is 33583.

        Adjusted fuel test vectors:

        At first, a module of mass 1969 requires 654 fuel. Then, this fuel requires 216 more fuel (654 / 3 - 2).
        216 then requires 70 more fuel, which requires 21 fuel, which requires 5 fuel, which requires no further fuel.
        So, the total fuel required for a module of mass 1969 is 654 + 216 + 70 + 21 + 5 = 966.

        The fuel required by a module of mass 100756 and its fuel is:
        33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346.
        """
        f = FuelCounterUpper()

        self.assertEqual(f.add_module(12), 2)
        self.assertEqual(f.add_module(14), 2)
        self.assertEqual(f.add_module(1969), 654)
        self.assertEqual(f.add_module(100756), 33583)

        self.assertEqual(f._do_adjusted_fuel({'fuel': 654, 'mass': 1969}), 966)
        self.assertEqual(f._do_adjusted_fuel({'fuel': 33583, 'mass': 100756}), 50346)

# EOF

"""
This file is part of Advent of Code 2019.

Coded by: <NAME> (<EMAIL>)
11 December 2019

NO COPYRIGHT
This work is dedicated to the public domain.  All rights have been
waived worldwide under copyright law, including all related and
neighboring rights, to the extent allowed by law.

You may copy, modify, distribute, and perform the work, even for
commercial purposes, all without asking permission.  See the
accompanying COPYRIGHT document.
"""

import unittest
from day1 import FuelCounterUpper


class TestFuelCounterUpper(unittest.TestCase):

    def test_add_module_types(self):
        """
        Checks for TypeError
        """
        f = FuelCounterUpper()
        with self.assertRaises(TypeError):
            # noinspection PyTypeChecker
            f.add_module('string')

    def test_add_module_values(self):
        """
        Checks for negative or excessively large values
        """
        f = FuelCounterUpper()
        with self.assertRaises(ValueError):
            f.add_module(-5)
        with self.assertRaises(ValueError):
            f.add_module(2**64)

    def test_set_attr(self):
        """
        Ensure we cannot overwrite the internal properties
        """
        f = FuelCounterUpper()
        with self.assertRaises(NotImplementedError):
            f.total_fuel = 1
        with self.assertRaises(NotImplementedError):
            f.total_mass = 1

    def test_del_attr(self):
        """
        Ensure we cannot delete the internal properties
        """
        f = FuelCounterUpper()
        with self.assertRaises(NotImplementedError):
            del f.total_fuel
        with self.assertRaises(NotImplementedError):
            del f.total_mass

    def test_given(self):
        """
        Runs the given test vectors from AoC:

        For a mass of 12, divide by 3 and round down to get 4, then subtract 2 to get 2.
        For a mass of 14, dividing by 3 and rounding down still yields 4, so the fuel required is also 2.
        For a mass of 1969, the fuel required is 654.
        For a mass of 100756, the fuel required is 33583.

        Adjusted fuel test vectors:

        At first, a module of mass 1969 requires 654 fuel. Then, this fuel requires 216 more fuel (654 / 3 - 2).
        216 then requires 70 more fuel, which requires 21 fuel, which requires 5 fuel, which requires no further fuel.
        So, the total fuel required for a module of mass 1969 is 654 + 216 + 70 + 21 + 5 = 966.

        The fuel required by a module of mass 100756 and its fuel is:
        33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346.
        """
        f = FuelCounterUpper()

        self.assertEqual(f.add_module(12), 2)
        self.assertEqual(f.add_module(14), 2)
        self.assertEqual(f.add_module(1969), 654)
        self.assertEqual(f.add_module(100756), 33583)

        self.assertEqual(f._do_adjusted_fuel({'fuel': 654, 'mass': 1969}), 966)
        self.assertEqual(f._do_adjusted_fuel({'fuel': 33583, 'mass': 100756}), 50346)

# EOF

This file is part of Advent of Code 2019.  Coded by: <NAME> (<EMAIL>) 11 December 2019  NO COPYRIGHT This work is dedicated to the public domain.  All rights have been waived worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.  You may copy, modify, distribute, and perform the work, even for commercial purposes, all without asking permission.  See the accompanying COPYRIGHT document. Checks for TypeError # noinspection PyTypeChecker Checks for negative or excessively large values Ensure we cannot overwrite the internal properties Ensure we cannot delete the internal properties Runs the given test vectors from AoC:          For a mass of 12, divide by 3 and round down to get 4, then subtract 2 to get 2.         For a mass of 14, dividing by 3 and rounding down still yields 4, so the fuel required is also 2.         For a mass of 1969, the fuel required is 654.         For a mass of 100756, the fuel required is 33583.          Adjusted fuel test vectors:          At first, a module of mass 1969 requires 654 fuel. Then, this fuel requires 216 more fuel (654 / 3 - 2).         216 then requires 70 more fuel, which requires 21 fuel, which requires 5 fuel, which requires no further fuel.         So, the total fuel required for a module of mass 1969 is 654 + 216 + 70 + 21 + 5 = 966.          The fuel required by a module of mass 100756 and its fuel is:         33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346. # EOF