File: imageasserter.h

package info (click to toggle)
aoflagger 3.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: cpp: 83,076; python: 10,187; sh: 260; makefile: 178
file content (47 lines) | stat: -rw-r--r-- 1,278 bytes parent folder | download | duplicates (2)
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
#ifndef AOFLAGGER_IMAGE_ASSERTER_H
#define AOFLAGGER_IMAGE_ASSERTER_H

#include "../../structures/image2d.h"

#include <boost/test/unit_test.hpp>

#include <string>
#include <stdexcept>
#include <sstream>

class ImageAsserter {
 public:
  static void AssertEqual(const Image2DCPtr& actual,
                          const Image2DCPtr& expected) {
    BOOST_CHECK_EQUAL(actual->Width(), expected->Width());
    BOOST_CHECK_EQUAL(actual->Height(), expected->Height());

    for (size_t y = 0; y < actual->Height(); ++y) {
      for (size_t x = 0; x < actual->Width(); ++x) {
        BOOST_CHECK_CLOSE(actual->Value(x, y), expected->Value(x, y), 1e-3);
      }
    }
  }

  static void AssertConstant(const Image2DCPtr& actual, const num_t& expected) {
    for (size_t y = 0; y < actual->Height(); ++y) {
      for (size_t x = 0; x < actual->Width(); ++x) {
        BOOST_CHECK_CLOSE(actual->Value(x, y), expected, 1e-3);
      }
    }
  }

  static void AssertFinite(const Image2DCPtr& actual) {
    size_t nonFinites = 0;
    for (size_t y = 0; y < actual->Height(); ++y) {
      for (size_t x = 0; x < actual->Width(); ++x) {
        if (!std::isfinite(actual->Value(x, y))) {
          ++nonFinites;
        }
      }
    }
    BOOST_CHECK_EQUAL(nonFinites, 0);
  }
};

#endif