Attached (new revision from my sandbox git repository). Any ideas on how to go about getting these tests to pass? Maybe there's some architecture changes that need to be made?
- Bryan http://heybryan.org/ 1 512 203 0507 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---
#!/usr/bin/python # sympy units shelltrance # Bryan Bishop ([email protected]) http://heybryan.org/ # 2009-06-21 from sympy import Symbol from sympy.physics import * # units.m import unittest # since this is a unit test (not a module), it should be ok to do the following from sympy import * class test_sympy_units(unittest.TestCase): def test_integration(self): t = Symbol("t") * units.s self.assertTrue(t.units == units.s) # integral of acceleration w.r.t time (t) is velocity acceleration = Symbol("a") * units.m * units.s**(-2) velocity = integrate(acceleration,t) self.assertTrue(velocity.units == (units.m/units.s)) def test_basic_stuff(self): # specify units when instantiating the symbol t = Symbol("t",units.s) # check that the units are correct self.assertTrue(t.units==units.s) # specifying units elsehow. mass = Symbol("m") * units.kg self.assertTrue(mass.units==units.kg) self.assertTrue(mass.units==units.g*1000) # from the previous unit test file version self.assertTrue((5*m/s)*day/km == 432) self.assertTrue(foot/meter == Rational('0.3048')) # light from the sun needs about 8.3 minutes to reach earth t = (1*units.au / units.speed_of_light).evalf() / units.minute self.assertTrue(abs(t - 8.31) < 0.1) self.assertTrue((units.m**2)**Rational(1,2) == units.m) self.assertTrue((units.m**Rational(1,2))**2 == units.m) def test_expr(self): (x,y) = symbols("xy") x = x * units.m y = y * units.m self.assertTrue((x+y+x-y)==2*x) self.assertTrue((x+y+x-y).units == units.m) self.assertTrue(((x+y)**2).units == units.m**2) distance = Symbol("d") * units.m # not sure about how subs() should work. # should it replace a variable entirely, or just the value of the variable? # i.e., what should be the result of: (x.subs(x,1)).units == units.m ? true or false? self.assertTrue((((distance+y)**2).subs(distance,1)).units == units.m**2) expanded = ((x+y)**2).expand() self.assertTrue(expanded.units == units.m**2) fractions = together(1/x + 1/y) self.assertTrue(fractions.units == units.m**(-1)) def test_calculus(self): x = Symbol("x") * units.m # charge -> current # R = V / I resistance = Symbol("R") * units.ohms voltage = Symbol("V") * units.volts current = Symbol("I") * units.amperes # precondition: R = V / I (in terms of units) self.assertTrue((voltage/current).units == resistance.units) # inductor # time-varying voltage v(t) across an inductor with an inductance L # .. and the time-varying current i(t) passing through it # v(t) = inductance * diff(current,time) voltage = Symbol("v") * units.volts time = Symbol("t") * units.s inductance = Symbol("L") * units.henrys current = Symbol("I") * units.amperes self.assertTrue((integrate(voltage,time)).units == (inductance * current).units) # sinusoidal alternating current (AC) through an inductor, producing a sinusoidal voltage # the amplitude of the voltage is proportional to the product of the amplitude (I_p) of the current # and the frequency (f) of the current # i(t) = I_p * sin(2 * pi * f * t) # di(t)/dt = 2 * pi * f * I_p * cos(2 * pi * f * t) current. # v(t) = 2 * pi * f * L * I_p * cos(2 * pi * f * t) # first derivative of charge is current # differentiate something besides time # heat transfer stuff # temperature gradient vs. distance (dT v. dx) # gradients # Arrhenius equation (concentration) .. concentration vs. distance (dC/dx) # time constants of chemistry equations # heat diffusion # second-order spring damper equation # RCL circuit (inductance, capacitance, resistance) def test_multiplication(self): # J = kg * m**2 * s**(-2) = N * m # N = kg * m * s**(-2) mass = Symbol("m1") * units.kg force = Symbol("f1") * units.s**(-2)*units.kg*units.m energy = mass*force self.assertTrue(energy.units==units.J) def test_addition(self): # the fun one? mass = Symbol("m2") * units.kg energy = Symbol("e1") * units.J self.assertRaises(mass*energy) if __name__ == '__main__': unittest.main()
