Skip to content

Commit

Permalink
part: bspline: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo authored and wwmayer committed Feb 18, 2017
1 parent 978978f commit 2b35bb3
Showing 1 changed file with 61 additions and 12 deletions.
73 changes: 61 additions & 12 deletions src/Mod/Part/TestPartApp.py
Expand Up @@ -20,6 +20,7 @@
#**************************************************************************

import FreeCAD, os, sys, unittest, Part
import copy
App = FreeCAD

#---------------------------------------------------------------------------
Expand All @@ -28,15 +29,63 @@


class PartTestCases(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartTest")

def testBoxCase(self):
self.Box = App.ActiveDocument.addObject("Part::Box","Box")
self.Doc.recompute()
self.failUnless(len(self.Box.Shape.Faces)==6)

def tearDown(self):
#closing doc
FreeCAD.closeDocument("PartTest")
#print ("omit clos document for debuging")
def setUp(self):
self.Doc = FreeCAD.newDocument("PartTest")

def testBoxCase(self):
self.Box = App.ActiveDocument.addObject("Part::Box","Box")
self.Doc.recompute()
self.failUnless(len(self.Box.Shape.Faces)==6)

def tearDown(self):
#closing doc
FreeCAD.closeDocument("PartTest")
#print ("omit clos document for debuging")

class PartTestBSplineCurve(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("PartTest")

poles = [[0, 0, 0], [1, 1, 0], [2, 0, 0]]
self.spline = Part.BSplineCurve()
self.spline.buildFromPoles(poles)

poles = [[0, 0, 0], [1, 1, 0], [2, 0, 0], [1, -1, 0]]
self.nurbs = Part.BSplineCurve()
self.nurbs.buildFromPolesMultsKnots(poles, (3, 1, 3),(0, 0.5, 1), False, 2)

def testProperties(self):
self.assertEqual(self.spline.Continuity, 'CN')
self.assertEqual(self.spline.Degree, 2)
self.assertEqual(self.spline.EndPoint, App.Vector(2, 0, 0))
self.assertEqual(self.spline.FirstParameter, 0.0)
self.assertEqual(self.spline.FirstUKnotIndex, 1)
self.assertEqual(self.spline.KnotSequence, [0.0, 0.0, 0.0, 1.0, 1.0, 1.0])
self.assertEqual(self.spline.LastParameter, 1.0)
self.assertEqual(self.spline.LastUKnotIndex, 2)
max_degree = self.spline.MaxDegree
self.assertEqual(self.spline.NbKnots, 2)
self.assertEqual(self.spline.NbPoles, 3)
self.assertEqual(self.spline.StartPoint, App.Vector(0.0, 0.0, 0.0))

def testGetters(self):
'''only check if the function doesn't crash'''
self.spline.getKnot(1)
self.spline.getKnots()
self.spline.getMultiplicities()
self.spline.getMultiplicity(1)
self.spline.getPole(1)
self.spline.getPoles()
self.spline.getPolesAndWeights()
self.spline.getResolution(0.5)
self.spline.getWeight(1)
self.spline.getWeights()

def testSetters(self):
spline = copy.deepcopy(self.spline)
spline.setKnot(1, 0.1)
spline.setPeriodic()
spline.setNotPeriodic()
# spline.setKnots()
# spline.setOrigin(2) # not working?
self.spline.setPole(1, App.Vector([1, 0, 0])) # first parameter 0 gives occ error

0 comments on commit 2b35bb3

Please sign in to comment.