Salome HOME
3128e212627c80efb214be677b1ad6bf1c464d74
[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,4,0,3*28)
27         res=pg.partition([(pd,1.),(pd,1.)])
28         assert(len(res)==2)
29         assert(isinstance(res[0],pilot.ContigPartDefinition))
30         assert(isinstance(res[1],pilot.ContigPartDefinition))
31         assert(res[0].getStart()==0 and res[0].getStop()==40)
32         assert(res[1].getStart()==40 and res[1].getStop()==84)
33         assert(sum([elt.getNumberOfCoresConsumed() for elt in res])==pg.getNumberOfCoresAvailable())
34         pd2=pilot.AllPartDefinition(pg,4)
35         assert(pd2.getNumberOfCoresConsumed()==84)
36         res=pg.partition([(pd2,1.),(pd2,1.),(pd2,1.)])
37         assert(len(res)==3)
38         assert(isinstance(res[0],pilot.ContigPartDefinition))
39         assert(isinstance(res[1],pilot.ContigPartDefinition))
40         assert(isinstance(res[2],pilot.ContigPartDefinition))
41         assert(res[0].getStart()==0 and res[0].getStop()==28)
42         assert(res[1].getStart()==28 and res[1].getStop()==56)
43         assert(res[2].getStart()==56 and res[2].getStop()==84)
44         #
45         pg.setData([("a0",2),("a1",8),("a2",8)])
46         res=pg.partition([(pilot.AllPartDefinition(pg,4),1.),(pilot.AllPartDefinition(pg,1),1.)])
47         assert(len(res)==2)
48         assert(isinstance(res[0],pilot.ContigPartDefinition))
49         assert(isinstance(res[1],pilot.NonContigPartDefinition))
50         assert(res[0].getStart()==2 and res[0].getStop()==10)
51         assert(res[1].getIDs()==(0,1,10,11,12,13,14,15,16,17))
52         pass
53
54     def test1(self):
55         """ test focused on complicated cut due to lack of cores"""
56         pg=pilot.PlayGround([("a0",13)])
57         pd=pilot.ContigPartDefinition(pg,4,0,13)
58         res=pg.partition([(pd,1.),(pd,1.)])
59         assert(len(res)==2)
60         assert(isinstance(res[0],pilot.ContigPartDefinition) and isinstance(res[1],pilot.ContigPartDefinition))
61         assert(res[0].getStart()==0 and res[0].getStop()==4)
62         assert(res[1].getStart()==4 and res[1].getStop()==12)# 1 core lost
63         #
64         pg=pilot.PlayGround([("a0",2),("a1",11)])
65         pd=pilot.ContigPartDefinition(pg,4,0,13)
66         res=pg.partition([(pd,1.),(pd,1.)])
67         assert(len(res)==2)
68         assert(isinstance(res[0],pilot.ContigPartDefinition) and isinstance(res[1],pilot.ContigPartDefinition))
69         assert(res[0].getStart()==2 and res[0].getStop()==6)
70         assert(res[1].getStart()==6 and res[1].getStop()==10)# 5 cores lost
71         pass
72     
73     pass
74
75 if __name__ == '__main__':
76     unittest.main()