1 /**************************************************************************
2 * test_bucket.cxx -- unit-tests for SGBucket class
4 * Copyright (C) 2014 James Turner - <zakalawe@mac.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 **************************************************************************/
23 #include <simgear/compiler.h>
33 #include <simgear/bucket/newbucket.hxx>
34 #include <simgear/misc/test_macros.hxx>
36 void testBucketSpans()
38 COMPARE(sg_bucket_span(0.0), 0.125);
39 COMPARE(sg_bucket_span(-20), 0.125);
40 COMPARE(sg_bucket_span(-40), 0.25);
41 COMPARE(sg_bucket_span(89.9), 12.0);
42 COMPARE(sg_bucket_span(88.1), 4.0);
43 COMPARE(sg_bucket_span(-89.9), 12.0);
48 SGBucket b1(0.0, 89.92);
49 SGBucket b2(10.0, 89.96);
50 COMPARE(b1.get_chunk_lat(), 89);
51 COMPARE(b1.get_chunk_lon(), 0);
52 COMPARE(b1.get_x(), 0);
53 COMPARE(b1.get_y(), 7);
55 COMPARE(b1.gen_index(), b2.gen_index());
57 SGBucket b3(-2, 89.88);
58 SGBucket b4(-7, 89.88);
59 COMPARE(b3.gen_index(), b4.gen_index());
62 SGBucket b5(-170, -89.88);
63 SGBucket b6(-179, -89.88);
65 COMPARE(b5.get_chunk_lat(), -90);
66 COMPARE(b5.get_chunk_lon(), -180);
67 COMPARE(b5.get_x(), 0);
68 COMPARE(b5.get_y(), 0);
69 COMPARE(b5.gen_index(), b6.gen_index());
71 // no automatic wrapping of these values occurs
72 SGBucket b7(200, 89.88);
73 COMPARE(b7.get_chunk_lon(), 192);
80 SGBucket b2(-1, 88.8);
81 COMPARE(b1.get_chunk_lon(), 0);
82 COMPARE(b1.get_chunk_lat(), 88);
83 VERIFY(b1.gen_index() != b2.gen_index());
85 SGBucket b3(176.1, 88.5);
86 COMPARE(b3.get_chunk_lon(), 176);
88 SGBucket b4(-178, 88.5);
89 // the fix for the polar cap issue, causes this to report -180,
91 COMPARE(b4.get_chunk_lon(), -180);
99 int main(int argc, char* argv[])
103 SGBucket b1(5.1, 55.05);
104 COMPARE(b1.get_chunk_lon(), 5);
105 COMPARE(b1.get_chunk_lat(), 55);
106 COMPARE(b1.get_x(), 0);
107 COMPARE(b1.get_y(), 0);
108 COMPARE(b1.gen_index(), 3040320);
109 COMPARE(b1.gen_base_path(), "e000n50/e005n55");
111 SGBucket b2(-10.1, -43.8);
112 COMPARE(b2.get_chunk_lon(), -11);
113 COMPARE(b2.get_chunk_lat(), -44);
114 COMPARE(b2.get_x(), 3);
115 COMPARE(b2.get_y(), 1); // latitude chunks numbered bottom to top, it seems
116 COMPARE(b2.gen_base_path(), "w020s50/w011s44");
118 SGBucket b3(123.48, 9.01);
119 COMPARE(b3.get_chunk_lon(), 123);
120 COMPARE(b3.get_chunk_lat(), 9);
121 COMPARE(b3.get_x(), 3);
122 COMPARE(b3.get_y(), 0);
123 COMPARE(b3.gen_base_path(), "e120n00/e123n09");
129 cout << "all tests passed OK" << endl;