def test_definitions(self): e1 = Equation(full_name="Jon's Law") e1.save(no_wiki=True) v1 = Variable(full_name="Jon's Constant") v1.save(no_wiki=True) e1.add_defined_var(v1.full_name) self.assertEqual(e1.defined_var.full_name, v1.full_name)
def test_infobase_add_SearchTerm(self): """ test linking a search term to an infobase or creating it if it doesn't exist. """ v1 = Variable(full_name="acceleration") v1.save(no_wiki=True) # creating a search term for the first time v1.add_SearchTerm("acc") try: s1 = SearchTerm.objects.get(term="acc") except (ObjectDoesNotExist, MultipleObjectsReturned), e: raise AssertionError
def test_infobase_add_from_sequence(self): v1 = Variable(full_name="acceleration") v1.save(no_wiki=True) u1 = Unit(full_name="ms") u1.save(no_wiki=True) u2 = Unit(full_name="meter") u2.save(no_wiki=True) u3 = Unit(full_name="second") u3.save(no_wiki=True) u1.make_composition_links("meter,second") v1.add_units_links("meter,second") try: uget1 = u1.composition_links.get(full_name="meter") uget2 = u1.composition_links.get(full_name="second") uget3 = v1.units_links.get(full_name="meter") uget4 = v1.units_links.get(full_name="second") except (ObjectDoesNotExist, MultipleObjectsReturned), e: raise AssertionError
def test_infobase_save(self): """ the save function is automated to add displaystyle to the latex, add a description and link from wikipedia, and full_name and quick_name as search terms. """ v1 = Variable(full_name="Newton's Second Law", quick_name="F=ma", representation="F=ma") v1.save() self.assertEqual(v1.representation, "$\\displaystyle{F=ma}$") self.assertEqual(v1.description_url, u"http://en.wikipedia.org/wiki/Newton%27s_laws_of_motion") # NOTE: The above represents a case where the description returned by # wikipedia is NOT what we want, so we need to revise it. try: s1 = SearchTerm.objects.get(term=v1.full_name) s2 = SearchTerm.objects.get(term=v1.quick_name) except ObjectDoesNotExist: raise AssertionError self.assertTrue(s1 in v1.search_terms.all()) self.assertTrue(s2 in v1.search_terms.all()) # test save method on existing object v1.description = "something else" v1.save() self.assertEqual(v1.description, "something else")
def test_equation_add_variables(self): e1 = Equation(full_name="Jon's Law") e1.save(no_wiki=True) v1 = Variable(full_name="Jon's Constant") v1.save(no_wiki=True) v2 = Variable(full_name="Jon's Operator") v2.save(no_wiki=True) v3 = Variable(full_name="Jon's Plus Sign") v3.save(no_wiki=True) e1.add_defined_var("Jon's Constant") e1.add_variables("Jon's Constant,Jon's Operator,Jon's Plus Sign") self.assertEqual(e1.defined_var.full_name, v1.full_name) self.assertTrue(v2 in e1.variables.all()) self.assertTrue(v3 in e1.variables.all()) self.assertFalse(v1 in e1.variables.all())
def test_infobase_strings(self): """ check representation with $ removed and confirm latex is valid """ v1 = Variable(representation=r'$a$') v1.save(no_wiki=True) self.assertEqual(v1.rep_without_dollars(), r'\displaystyle{a}')
u1.save(no_wiki=True) u2 = Unit(full_name="meter") u2.save(no_wiki=True) u3 = Unit(full_name="second") u3.save(no_wiki=True) u1.make_composition_links("meter,second") v1.add_units_links("meter,second") try: uget1 = u1.composition_links.get(full_name="meter") uget2 = u1.composition_links.get(full_name="second") uget3 = v1.units_links.get(full_name="meter") uget4 = v1.units_links.get(full_name="second") except (ObjectDoesNotExist, MultipleObjectsReturned), e: raise AssertionError v2 = Variable(full_name="Jon's Constant") v2.save(no_wiki=True) u4 = Unit(full_name="kilogram") u4.save(no_wiki=True) u4.make_composition_links("base") self.assertFalse(bool(u4.composition_links.all())) def test_definitions(self): e1 = Equation(full_name="Jon's Law") e1.save(no_wiki=True) v1 = Variable(full_name="Jon's Constant") v1.save(no_wiki=True) e1.add_defined_var(v1.full_name) self.assertEqual(e1.defined_var.full_name, v1.full_name) def test_equation_add_variables(self): e1 = Equation(full_name="Jon's Law")