1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #include <gtest/gtest.h>
19 #include "ignition/common/MaterialDensity.hh"
20 #include "test/util.hh"
21 
22 using namespace ignition;
23 using namespace common;
24 
25 class MaterialDensityTest : public ignition::testing::AutoLogFixture { };
26 
27 /////////////////////////////////////////////////
TEST_F(MaterialDensityTest,Init)28 TEST_F(MaterialDensityTest, Init)
29 {
30   EXPECT_TRUE(!MaterialDensity::Materials().empty());
31 }
32 
33 /////////////////////////////////////////////////
TEST_F(MaterialDensityTest,Accessors)34 TEST_F(MaterialDensityTest, Accessors)
35 {
36   {
37     double density = MaterialDensity::Density("Aluminum");
38     double density2 = MaterialDensity::Density(MaterialDensity::Type::ALUMINUM);
39 
40     EXPECT_DOUBLE_EQ(density, 2700);
41     EXPECT_DOUBLE_EQ(density, density2);
42   }
43   {
44     double density = MaterialDensity::Density("Notfoundium");
45     EXPECT_DOUBLE_EQ(density, -1.0);
46   }
47   {
48     MaterialDensity::Type material;
49     double density;
50     std::tie(material, density) = MaterialDensity::Nearest(19300.0);
51     EXPECT_EQ(material, MaterialDensity::Type::TUNGSTEN);
52     EXPECT_DOUBLE_EQ(density,
53         MaterialDensity::Density(MaterialDensity::NearestMaterial(19300.0)));
54   }
55   {
56     MaterialDensity::Type material;
57     double density;
58     std::tie(material, density) = MaterialDensity::Nearest(1001001.001, 1e-3);
59     EXPECT_EQ(material, MaterialDensity::Type::END);
60     EXPECT_DOUBLE_EQ(density, -1.0);
61   }
62   {
63     MaterialDensity::Type material;
64     double density;
65     std::tie(material, density) = MaterialDensity::Nearest(1001001.001);
66     EXPECT_EQ(material, MaterialDensity::Type::TUNGSTEN);
67     EXPECT_DOUBLE_EQ(density, 19300);
68   }
69 }
70 
71 /////////////////////////////////////////////////
main(int argc,char ** argv)72 int main(int argc, char **argv)
73 {
74   ::testing::InitGoogleTest(&argc, argv);
75   return RUN_ALL_TESTS();
76 }
77