Skip to content
Snippets Groups Projects
JSONInstrumentBuilderTest.h 2.42 KiB
Newer Older
Moore's avatar
Moore committed
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
//     NScD Oak Ridge National Laboratory, European Spallation Source
//     & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#ifndef MANTID_NEXUSGEOMETRY_JSONINSTRUMENTBUILDERTEST_H_
#define MANTID_NEXUSGEOMETRY_JSONINSTRUMENTBUILDERTEST_H_

#include "MantidGeometry/Instrument.h"
Moore's avatar
Moore committed
#include "MantidNexusGeometry/JSONGeometryParser.h"
Moore's avatar
Moore committed
#include "MantidNexusGeometry/JSONInstrumentBuilder.h"
#include "MantidTestHelpers/JSONGeometryParserTestHelper.h"
#include <cxxtest/TestSuite.h>
Moore's avatar
Moore committed
#include <json/json.h>
Moore's avatar
Moore committed

using namespace Mantid;
Moore's avatar
Moore committed
using Mantid::NexusGeometry::JSONInstrumentBuilder;

class JSONInstrumentBuilderTest : 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 JSONInstrumentBuilderTest *createSuite() {
    return new JSONInstrumentBuilderTest();
  }
  static void destroySuite(JSONInstrumentBuilderTest *suite) { delete suite; }
Moore's avatar
Moore committed

  void test_constructor_pass_valid_instrument() {
    auto json = TestHelpers::getFullJSONInstrumentSimpleWithChopper();
    TS_ASSERT_THROWS_NOTHING((JSONInstrumentBuilder(json)));
  }
Moore's avatar
Moore committed

  void test_constructor_fail_invalid_instrument() {
    TS_ASSERT_THROWS(JSONInstrumentBuilder(""), std::invalid_argument);
Moore's avatar
Moore committed
  }

  void test_build_geometry() {
    auto json = TestHelpers::getFullJSONInstrumentSimpleWithChopper();
    JSONInstrumentBuilder builder(json);
    TS_ASSERT_THROWS_NOTHING((builder.buildGeometry()));
  }
Moore's avatar
Moore committed

  void test_simple_instrument() {
    auto json = TestHelpers::getFullJSONInstrumentSimpleWithMonitor();
    JSONInstrumentBuilder builder(json);
    auto instrument = builder.buildGeometry();

    TS_ASSERT_EQUALS(instrument->getFullName(), "SimpleInstrument");
    TS_ASSERT(instrument->getComponentByName("detector_1"));
    TS_ASSERT_EQUALS(instrument->getNumberDetectors(false), 5); // 5 with
                                                                // monitor

    auto sample = instrument->getSample();
    TS_ASSERT_EQUALS(sample->getName(), "sample");
Moore's avatar
Moore committed

    detid_t min_id;
    detid_t max_id;
    instrument->getMinMaxDetectorIDs(min_id, max_id);
    TS_ASSERT_EQUALS(min_id, 1);
    TS_ASSERT_EQUALS(max_id, 90000); // monitor
  }
};
Moore's avatar
Moore committed

Moore's avatar
Moore committed
#endif /* MANTID_NEXUSGEOMETRY_JSONINSTRUMENTBUILDERTEST_H_ */