def test_examples(self):
        """Test NanoFactory examples"""

        # 1. Create and run factory for example 1
        myfactory = nanofactory.NanoFactory(text=EXP1_TEXT)
        self.assertEqual(myfactory.produce('1 FUEL'), True)
        self.assertEqual(myfactory.ore, EXP1_ORE)

        # 2. Create and run factory for example 2
        myfactory = nanofactory.NanoFactory(text=EXP2_TEXT)
        self.assertEqual(myfactory.produce('1 FUEL'), True)
        self.assertEqual(myfactory.ore, EXP2_ORE)

        # 3. Create and run factory for example 3
        myfactory = nanofactory.NanoFactory(text=EXP3_TEXT)
        self.assertEqual(myfactory.produce('1 FUEL'), True)
        self.assertEqual(myfactory.ore, EXP3_ORE)

        # 4. Create and run factory for example 4
        myfactory = nanofactory.NanoFactory(text=EXP4_TEXT)
        self.assertEqual(myfactory.produce('1 FUEL'), True)
        self.assertEqual(myfactory.ore, EXP4_ORE)

        # 5. Create and run factory for example 5
        myfactory = nanofactory.NanoFactory(text=EXP5_TEXT)
        self.assertEqual(myfactory.produce('1 FUEL'), True)
        self.assertEqual(myfactory.ore, EXP5_ORE)
    def test_text_init(self):
        """Test NanoFactory object creation with text"""

        # 1. Create a factory with reactions in text
        myfactory = nanofactory.NanoFactory(text=EXP1_TEXT)

        # 2. Make sure it has the default values
        self.assertEqual(len(myfactory.resources), 0)
        self.assertEqual(len(myfactory.recipes), 6)
        self.assertEqual(myfactory.ore, 0)

        # 3. Test producing ore
        self.assertEqual(myfactory.produce('3 ORE'), True)
        self.assertEqual(myfactory.ore, 3)
        self.assertEqual(myfactory.produce('1 ORE'), True)
        self.assertEqual(myfactory.ore, 4)
        myfactory.ore = 0

        # 4. Test a simple recipe
        self.assertEqual(myfactory.produce('1 B'), True)
        self.assertEqual(myfactory.resources['B'], 0)
        self.assertEqual(myfactory.ore, 1)
        myfactory.ore = 0

        # 5. Test a silightly mor complicated recipe
        self.assertEqual(myfactory.produce('1 C'), True)
        self.assertEqual(myfactory.resources['A'], 3)
        self.assertEqual(myfactory.ore, 11)
        myfactory.ore = 0

        # 6. And now try to make FUEL
        self.assertEqual(myfactory.produce('1 FUEL'), True)
        self.assertEqual(myfactory.resources['A'], 5)
        self.assertEqual(myfactory.ore, EXP1_ORE)
        myfactory.ore = 0
    def test_empty_init(self):
        """Test default NanoFactory object creation"""

        # 1. Create a default factory
        myfactory = nanofactory.NanoFactory()

        # 2. Make sure it has the default values
        self.assertEqual(myfactory.resources, {})
        self.assertEqual(myfactory.recipes, {})
        self.assertEqual(myfactory.ore, 0)

        # 3. Test producing ore
        self.assertEqual(myfactory.produce('3 ORE'), True)
        self.assertEqual(myfactory.ore, 3)
        self.assertEqual(myfactory.produce('1 ORE'), True)
        self.assertEqual(myfactory.ore, 4)
Example #4
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the factory
    factory = nanofactory.NanoFactory(text=input_lines)

    # 2. Determine the maximum FUEL that can be produced from a trillion ORE
    solution = factory.fuel_per_trillion(watch=args.verbose)
    if solution is not None:
        print(
            "The maximal amount of FUEL that can be produded with a trillion ORE is %d"
            % (solution))
    else:
        solution = None
        print("Unable to produce FUEL")

    # 3. Return result
    return solution is not None
Example #5
0
def part_one(args, input_lines):
    "Process part one of the puzzle"

    # 1. Create the factory
    factory = nanofactory.NanoFactory(text=input_lines)

    # 2. Produced the desired item and quanity
    produced = factory.produce('1 FUEL', watch=args.verbose)
    if produced:
        solution = factory.ore
        print("The amount of ORE required to produce exactly %s is %d" %
              ('1 FUEL', solution))
    else:
        solution = None
        print("Unable to produce exactly %s" % ('1 FUEL'))

    # 3. Return result
    return solution is not None
    def not_test_trillion5(self):
        """Test NanoFactory fuel per one trillion ore for example 5"""

        # 1. Create and get fuel amount for example 5
        myfactory = nanofactory.NanoFactory(text=EXP5_TEXT)
        self.assertEqual(myfactory.fuel_per_trillion(), EXP5_TRILLION)
Example #7
0
import sys
import nanofactory

#import logging
#logging.getLogger("nanofactory").setLevel(logging.DEBUG)

filename = sys.argv[1]

print(nanofactory.NanoFactory(filename).produce(1, 'FUEL'))

Example #8
0
import sys
import nanofactory

#import logging
#logging.getLogger("nanofactory").setLevel(logging.DEBUG)

filename = sys.argv[1]


print(nanofactory.NanoFactory(filename).output_capacity(
    1000000000000,
    'FUEL'
    ))