File: test_minmax.cpp

package info (click to toggle)
libosmium 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,564 kB
  • sloc: cpp: 53,570; sh: 148; makefile: 19
file content (62 lines) | stat: -rw-r--r-- 1,408 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
#include "catch.hpp"

#include <osmium/osm/timestamp.hpp>
#include <osmium/util/minmax.hpp>

#include <cstdint>
#include <limits>

TEST_CASE("min_op numeric") {
    osmium::min_op<int> x;
    REQUIRE(x() == std::numeric_limits<int>::max());

    x.update(17);
    REQUIRE(x() == 17);

    x.update(10);
    REQUIRE(x() == 10);

    x.update(22);
    REQUIRE(x() == 10);
}

TEST_CASE("max_op numeric") {
    osmium::max_op<uint32_t> x;
    REQUIRE(x() == 0);

    x.update(17);
    REQUIRE(x() == 17);

    x.update(10);
    REQUIRE(x() == 17);

    x.update(22);
    REQUIRE(x() == 22);
}

TEST_CASE("min_op timestamp") {
    osmium::min_op<osmium::Timestamp> x;

    x.update(osmium::Timestamp("2010-01-01T00:00:00Z"));
    REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z");

    x.update(osmium::Timestamp("2015-01-01T00:00:00Z"));
    REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z");

    x.update(osmium::Timestamp("2000-01-01T00:00:00Z"));
    REQUIRE(x().to_iso() == "2000-01-01T00:00:00Z");
}

TEST_CASE("max_op timestamp") {
    osmium::max_op<osmium::Timestamp> x;

    x.update(osmium::Timestamp("2010-01-01T00:00:00Z"));
    REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z");

    x.update(osmium::Timestamp("2015-01-01T00:00:00Z"));
    REQUIRE(x().to_iso() == "2015-01-01T00:00:00Z");

    x.update(osmium::Timestamp("2000-01-01T00:00:00Z"));
    REQUIRE(x().to_iso() == "2015-01-01T00:00:00Z");
}