File: test_kpoint.cc

package info (click to toggle)
eckit 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 11,044 kB
  • sloc: cpp: 111,103; ansic: 2,826; yacc: 590; lex: 361; python: 302; sh: 162; makefile: 53
file content (115 lines) | stat: -rw-r--r-- 2,390 bytes parent folder | download | duplicates (5)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * (C) Copyright 1996- ECMWF.
 *
 * This software is licensed under the terms of the Apache Licence Version 2.0
 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
 * In applying this licence, ECMWF does not waive the privileges and immunities
 * granted to it by virtue of its status as an intergovernmental organisation nor
 * does it submit to any jurisdiction.
 */

#include "eckit/geometry/Point3.h"
#include "eckit/testing/Test.h"

using namespace std;
using namespace eckit;
using namespace eckit::testing;
using namespace eckit::geometry;

namespace eckit::test {

CASE("KPoint Inits to Zero") {
    Point3 p;

    EXPECT(p[XX] == 0.);
    EXPECT(p[YY] == 0.);
    EXPECT(p[ZZ] == 0.);
}

CASE("KPoint Inits to Array") {
    Point3 p = {1.0, 2.0, 3.0};

    EXPECT(p[XX] == 1.0);
    EXPECT(p[YY] == 2.0);
    EXPECT(p[ZZ] == 3.0);
}

CASE("KPoint addition") {
    Point3 p1 = {1.0, 2.0, 3.0};
    Point3 p2 = {1.0, 2.0, 3.0};

    Point3 r = p1 + p2;

    EXPECT(r[XX] == 2.0);
    EXPECT(r[YY] == 4.0);
    EXPECT(r[ZZ] == 6.0);
}

CASE("KPoint subtraction") {
    Point3 p1 = {2.0, 5.0, 7.0};
    Point3 p2 = {1.0, 2.0, 3.0};

    Point3 r = p1 - p2;

    EXPECT(r[XX] == 1.0);
    EXPECT(r[YY] == 3.0);
    EXPECT(r[ZZ] == 4.0);
}

CASE("KPoint subtraction") {
    Point3 p1 = {2.0, 5.0, 7.0};
    Point3 p2 = {1.0, 2.0, 3.0};

    Point3 r = p1 - p2;

    EXPECT(r[XX] == 1.0);
    EXPECT(r[YY] == 3.0);
    EXPECT(r[ZZ] == 4.0);
}

CASE("KPoint scaling") {
    Point3 p1 = {1.0, 2.0, 3.0};

    Point3 r = p1 * 42.0;

    EXPECT(r[XX] == 42.0);
    EXPECT(r[YY] == 84.0);
    EXPECT(r[ZZ] == 126.0);
}

CASE("KPoint equality") {
    Point3 p1 = {1.0, 2.0, 3.0};
    Point3 p2 = {1.0, 2.0, 3.0};

    EXPECT(p1 == p2);
}

CASE("KPoint inequality") {
    Point3 p1 = {1.0, 2.0, 3.0};
    Point3 p2 = {1.0, 2.0, 4.0};

    EXPECT(p1 != p2);
}

CASE("KPoint comparison") {
    Point3 p1 = {2.0, 1.0, 0.0};
    Point3 p2 = {1.0, 2.0, 4.0};

    EXPECT(p2 < p1);
}

CASE("KPoint distance2 comparison") {
    Point3 zz;
    Point3 p1 = {2.0, 1.0, 0.0};
    Point3 p2 = {1.0, 2.0, 4.0};

    EXPECT(p1.distance2(zz) < p2.distance2(zz));
}

}  // namespace eckit::test

//----------------------------------------------------------------------------------------------------------------------

int main(int argc, char** argv) {
    return run_tests(argc, argv);
}