DataBlockTest.h 2.13 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9
10
11

#include <cxxtest/TestSuite.h>

#include "MantidDataHandling/DataBlock.h"
12
#include "MantidDataHandling/DataBlockGenerator.h"
13

14
using Mantid::specnum_t;
Stephen's avatar
Stephen committed
15
using Mantid::DataHandling::DataBlock;
16
17
18
19
20
21

class DataBlockTest : public CxxTest::TestSuite {
public:
  // This pair of boilerplate methods prevent the suite being created statically
  // This means the constructor isn't called when running other tests
  static DataBlockTest *createSuite() { return new DataBlockTest(); }
22
  static void destroySuite(DataBlockTest *suite) { delete suite; }
23

24
  void test_that_data_block_produces_generator_which_generates_range() {
25
    // Arrange
26
27
    specnum_t min = 2;
    specnum_t max = 8;
28
29
30
31
32
33
34
    DataBlock dataBlock;
    // Act
    dataBlock.setMinSpectrumID(min);
    dataBlock.setMaxSpectrumID(max);
    auto generator = dataBlock.getGenerator();

    // Assert
35
    std::vector<specnum_t> expected = {2, 3, 4, 5, 6, 7, 8};
36
37
38
39
    size_t index = 0;
    for (; !generator->isDone(); generator->next(), ++index) {
      TSM_ASSERT_EQUALS("Should take elements out of the DataBlock interval",
                        expected[index], generator->getValue());
40
    }
41
42
43

    TSM_ASSERT_EQUALS("Should have been incremented 7 times", index,
                      expected.size());
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

  void test_that_two_data_blocks_are_equal() {
    // Arrange
    DataBlock block1(1, 10, 3);
    block1.setMinSpectrumID(5);
    block1.setMaxSpectrumID(15);

    // Act + Assert
    TSM_ASSERT("Should be equal", block1 == block1);
  }

  void test_that_two_data_blocks_are_not_equal() {
    // Arrange
    DataBlock block1(1, 10, 3);
    block1.setMinSpectrumID(5);
    block1.setMaxSpectrumID(15);

    DataBlock block2(2, 10, 3);
    block2.setMinSpectrumID(5);
    block2.setMaxSpectrumID(15);

    // Act + Assert
    TSM_ASSERT("Should not be equal", !(block1 == block2));
  }
69
};