# -*- coding:utf-8 -*-
#! /usr/bin/env python3.4
#
#    Argon - An experimental chemistry procedure manager
#
#    Copyright (C) 2014 Mathias Mamboury
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest
from species import Species
from reaction import Reaction

class TestReaction(unittest.TestCase):

    def setUp(self):
        self._limiting = Species("Limiting", 100)
        self._limiting.set_n(0.001)
        self._reactant2 = Species("Reactant #1", 200)
        self._reactant3 = Species("Reactant #2", 300)
        self._product = Species("Product", 400)

    def test_add_get_limiting_reactant(self):
        reaction = Reaction()
        reaction.add_limiting_reactant(self._limiting)
        self.assertEqual(reaction.get_limiting_reactant().n(), 0.001)

    def test_add_get_reactant(self):
        reaction = Reaction()
        reaction.add_limiting_reactant(self._limiting)
        reaction.add_reactant(self._reactant2, 2)
        reaction.add_reactant(self._reactant3, 3)
        self.assertEqual(reaction.get_non_limiting_reactants()[0].n(), 0.002)
        self.assertEqual(reaction.get_non_limiting_reactants()[1].n(), 0.003)

    def test_add_get_product(self):
        reaction = Reaction()
        reaction.add_product(self._product, 0.4)
        self.assertEqual(reaction.get_product().n(), 0.001)

    def test_get_yield(self):
        reaction = Reaction()
        reaction.add_limiting_reactant(self._limiting)
        reaction.add_product(self._product, 0.3)
        self.assertEqual(reaction.get_yield(), 75)

if __name__ == '__main__':
    unittest.main()

