def test_linear_coefficient(self): p1 = p.Point(2, 2.5) p2 = p.Point(4, 4) line = l.Line() line.create(p1, p2) assert (float(line.Linear) == (1.0))
def test_vector(self): a = v.Vector(3, 4) assert (a.i == 3 and a.j == 4) b = v.Vector(p.Point(3, 5)) assert (b.i == 3 and b.j == 5) c = v.Vector(p.Point(7, 42), p.Point(-2, 30)) assert (c.i == -9 and c.j == -12)
def test_b_coefficient(self): p1 = p.Point(2, 2.5) p2 = p.Point(4, 4) line = l.Line() line.create(p1, p2) assert (float(line.B) == 2.0)
def test_angular_coefficient(self): p1 = p.Point(2, 2.5) p2 = p.Point(4, 4) line = l.Line() line.create(p1, p2) assert (float(line.Angular) == (0.75))
def test_line_equation(self): p1 = p.Point(2, 2) p2 = p.Point(4, 4) line = l.Line() line.create(p1, p2) assert (type(line.equation()) == str)
def test_ACoefficient(self): p1 = p.Point(2, 2.5) p2 = p.Point(4, 4) line = l.Line() line.create(p1, p2) assert (float(line.A) == (-1.5))
def test_instance_two_points(self): p1 = p.Point(2, 2) p2 = p.Point(4, 4) line = l.Line() line.create(p1, p2) assert (str(line) == "-2.0x+2.0y+0=0")
def create_via_equation(self, equation): """ This function is for getting a line created by a line equation """ self.createdby = "equation" regex = re.compile( r'([\+\-]?\d*x)\s*([\+\-]\d*y)\s*([\+\-]\d*)\s*\=\s*([\+\-]?\d*)') values = regex.findall(equation) values = values[0] self.A = "+1" if values[0] == 'x' or values[ 0] == '+x' else "-1" if values[0] == '-x' else values[0][:-1] self.B = "+1" if values[ 1] == '+y' else "-1" if values[1] == '-y' else values[1][:-1] self.C = values[2] self.Angular = (float(self.A) / float(self.B)) self.Angulation = degrees(atan(float(self.Angular))) self.PointOne = p.Point(float(self.C) / float(self.A), 0) self.PointTwo = p.Point(0, float(self.C) / float(self.B))
def test_instance_one_point_and_slope(self): p1 = p.Point(4, 4.5) line = l.Line() line.create_via_slope(p1, 1) assert (line.equation() == "y=1x+0.5")
def test_quadrant(self): assert (p.Point(2, -8).quadrant() == 4)
def test_midpoint(self): assert (str(p.Point(9, 8).midpoint(p.Point(1, 2))) == "Point(5.0, 5.0)")
def test_equal(self): a = v.Vector(34, 12) b = v.Vector(p.Point(34, 12)) c = v.Vector(p.Point(12, -4), p.Point(46, 8)) assert (a.equal(b) and a.equal(c))
def test_distance(self): assert (p.Point(9, 8).distance(p.Point(1, 2)) == 10)