1+ % test the Navigation abstract superclass
2+
3+ function tests = NavigationTest
4+ tests = functiontests(localfunctions );
5+ end
6+
7+
8+ function map_test(tc )
9+ map = zeros(10 ,10 );
10+ map(2 ,3 ) = 1 ;
11+
12+ nav = Bug2(map ); % we can't instantiate Navigation because it's abstract
13+
14+ %% test isoccupied method
15+ % row vector
16+ tc .verifyTrue( nav .isoccupied([3 ,2 ]) );
17+ tc .verifyFalse( nav .isoccupied([3 ,3 ]) );
18+
19+ % column vector
20+ tc .verifyTrue( nav .isoccupied([3 ,2 ]' ) );
21+ tc .verifyFalse( nav .isoccupied([3 ,3 ]' ) );
22+
23+ % separate args
24+ tc .verifyTrue( nav .isoccupied(3 ,2 ) );
25+ tc .verifyFalse( nav .isoccupied(3 ,3 ) );
26+
27+ % out of bound
28+ tc .verifyTrue( nav .isoccupied([20 20 ]) );
29+
30+ % multiple points
31+ tc .verifyEqual( nav .isoccupied([3 2 ; 20 20 ; 3 3 ]' ), [true true false ] );
32+
33+ tc .verifyEqual( nav .isoccupied([3 20 3 ], [2 20 3 ]), [true true false ] );
34+ tc .verifyEqual( nav .isoccupied([3 20 3 ]' , [2 20 3 ]), [true true false ] );
35+ tc .verifyEqual( nav .isoccupied([3 20 3 ], [2 20 3 ]' ), [true true false ] );
36+ tc .verifyEqual( nav .isoccupied([3 20 3 ]' , [2 20 3 ]' ), [true true false ] );
37+
38+ %% test inflation option
39+ nav = Bug2(map , ' inflate' , 1 );
40+ tc .verifyTrue( nav .isoccupied([3 ,2 ]) );
41+ tc .verifyTrue( nav .isoccupied([3 ,3 ]) );
42+ tc .verifyFalse( nav .isoccupied([3 ,4 ]) );
43+ end
44+
45+ function maptype_test(tc )
46+
47+ %% logical map
48+ map = zeros(10 ,10 , ' logical' );
49+ map(2 ,3 ) = true ;
50+
51+ nav = Bug2(map ); % we can't instantiate Navigation because it's abstract
52+
53+ tc .verifyTrue( nav .isoccupied([3 ,2 ]) );
54+ tc .verifyFalse( nav .isoccupied([3 ,3 ]) );
55+
56+ %% uint8 map
57+ map = zeros(10 ,10 , ' uint8' );
58+ map(2 ,3 ) = 1 ;
59+
60+ nav = Bug2(map ); % we can't instantiate Navigation because it's abstract
61+
62+ tc .verifyTrue( nav .isoccupied([3 ,2 ]) );
63+ tc .verifyFalse( nav .isoccupied([3 ,3 ]) );
64+ end
65+
66+ function rand_test(tc )
67+
68+ nav = Bug2(); % we can't instantiate Navigation because it's abstract
69+
70+ %% test random number generator
71+ r = nav .randn ;
72+ tc .verifySize(r , [1 1 ]);
73+ tc .verifyInstanceOf(r , ' double' );
74+ r = nav .randn(2 ,2 );
75+ tc .verifySize(r , [2 2 ]);
76+ end
77+
78+ function randi_test(tc )
79+
80+ nav = Bug2(); % we can't instantiate Navigation because it's abstract
81+
82+ %% test integer random number generator
83+ r = nav .randi(10 );
84+ tc .verifySize(r , [1 1 ]);
85+ tc .verifyEqual(r , floor(r )); % is it an integer value
86+ tc .verifyInstanceOf(r , ' double' );
87+ r = nav .randi(10 , 2 ,2 );
88+ tc .verifySize(r , [2 2 ]);
89+ tc .verifyEqual(r , floor(r ));
90+
91+ % check range
92+ r = nav .randi(10 , 100 ,1 );
93+ tc .verifyTrue(min(r ) >= 1 );
94+ tc .verifyTrue(max(r ) <= 10 );
95+ end
0 commit comments