Salome HOME
Ooops
[modules/yacs.git] / src / engine_swig / testPlayGround0.py
1 # Copyright (C) 2006-2017  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import pilot
21 import unittest
22
23 class TestPlayGround0(unittest.TestCase):
24     def test0(self):
25         pg=pilot.PlayGround([("a0",28),("a1",28),("a2",28)])
26         pd=pilot.ContigPartDefinition(pg,0,3*28)
27         cw=pilot.ComplexWeight(0.,1.,4)
28         res=pg.partition([(pd,cw),(pd,cw)],[4,4])
29         assert(len(res)==2)
30         assert(isinstance(res[0],pilot.ContigPartDefinition))
31         assert(isinstance(res[1],pilot.ContigPartDefinition))
32         assert(res[0].getStart()==0 and res[0].getStop()==44)
33         assert(res[1].getStart()==44 and res[1].getStop()==84)
34         assert(sum([elt.getNumberOfCoresConsumed() for elt in res])==pg.getNumberOfCoresAvailable())
35         pd2=pilot.AllPartDefinition(pg)
36         assert(pd2.getNumberOfCoresConsumed()==84)
37         res=pg.partition([(pd2,cw),(pd2,cw),(pd2,cw)],[4,4,4])
38         assert(len(res)==3)
39         assert(isinstance(res[0],pilot.ContigPartDefinition))
40         assert(isinstance(res[1],pilot.ContigPartDefinition))
41         assert(isinstance(res[2],pilot.ContigPartDefinition))
42         assert(res[0].getStart()==0 and res[0].getStop()==28)
43         assert(res[1].getStart()==28 and res[1].getStop()==56)
44         assert(res[2].getStart()==56 and res[2].getStop()==84)
45         #
46         pg.setData([("a0",2),("a1",8),("a2",8)])
47         cw2=pilot.ComplexWeight(0.,4.,1)
48         res=pg.partition([(pilot.AllPartDefinition(pg),cw),(pilot.AllPartDefinition(pg),cw)],[4,1])
49         assert(len(res)==2)
50         assert(isinstance(res[0],pilot.ContigPartDefinition))
51         assert(isinstance(res[1],pilot.NonContigPartDefinition))
52         assert(res[0].getStart()==2 and res[0].getStop()==10)
53         assert(res[1].getIDs()==(0,1,10,11,12,13,14,15,16,17))
54         pass
55
56     def test1(self):
57         """ test focused on complicated cut due to lack of cores"""
58         pg=pilot.PlayGround([("a0",13)])
59         pd=pilot.ContigPartDefinition(pg,0,13)
60         cw=pilot.ComplexWeight(0.,1.,4)
61         cw2=pilot.ComplexWeight(0.,2.,4)
62         res=pg.partition([(pd,cw),(pd,cw2)],[4,4])
63         assert(len(res)==2)
64         assert(isinstance(res[0],pilot.ContigPartDefinition) and isinstance(res[1],pilot.ContigPartDefinition))
65         assert(res[0].getStart()==0 and res[0].getStop()==4)
66         assert(res[1].getStart()==4 and res[1].getStop()==12)# 1 core lost
67         #
68         pg=pilot.PlayGround([("a0",2),("a1",27)])
69         cw3=pilot.ComplexWeight(0.,20,1)
70         cw4=pilot.ComplexWeight(0.,1.,8)
71         pd=pilot.ContigPartDefinition(pg,0,29)
72         res=pg.partition([(pd,cw3),(pd,cw4)],[4,8])
73         assert(len(res)==2)
74         assert(isinstance(res[0],pilot.ContigPartDefinition) and isinstance(res[1],pilot.ContigPartDefinition))
75         assert(res[0].getStart()==10 and res[0].getStop()==26)
76         assert(res[1].getStart()==2 and res[1].getStop()==10)# 5 cores lost
77         pass
78     
79     pass
80
81 if __name__ == '__main__':
82     unittest.main()