forked from gazebosim/sdformat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpySphere_TEST.py
81 lines (55 loc) · 2.05 KB
/
pySphere_TEST.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright (C) 2022 Open Source Robotics Foundation
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import math
from sdformat13 import Sphere
import unittest
class SphereTEST(unittest.TestCase):
def test_default_construction(self):
sphere = Sphere();
self.assertEqual(1.0, sphere.radius());
sphere.set_radius(0.5);
self.assertEqual(0.5, sphere.radius());
def test_assignment(self):
sphere = Sphere();
sphere.set_radius(0.2);
sphere2 = sphere;
self.assertEqual(0.2, sphere2.radius());
def test_copy_construction(self):
sphere = Sphere();
sphere.set_radius(0.2);
sphere2 = Sphere(sphere);
self.assertEqual(0.2, sphere2.radius());
self.assertEqual(4.0/3.0*math.pi*math.pow(0.2, 3), sphere2.shape().volume());
self.assertEqual(0.2, sphere2.shape().radius());
def test_deepcopy_construction(self):
sphere = Sphere();
sphere.set_radius(0.2);
sphere2 = copy.deepcopy(sphere);
self.assertEqual(0.2, sphere2.radius());
def test_deepcopy_after_assignment(self):
sphere1 = Sphere();
sphere1.set_radius(0.1);
sphere2 = Sphere();
sphere2.set_radius(0.2);
# This is similar to what swap does
tmp = copy.deepcopy(sphere1);
sphere1 = sphere2;
sphere2 = tmp;
self.assertEqual(0.2, sphere1.radius());
self.assertEqual(0.1, sphere2.radius());
def test_shape(self):
sphere = Sphere();
self.assertEqual(1.0, sphere.radius());
sphere.shape().set_radius(0.123);
self.assertEqual(0.123, sphere.radius());
if __name__ == '__main__':
unittest.main()