forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HistogramTest.h
1157 lines (1007 loc) · 41.5 KB
/
HistogramTest.h
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include <cxxtest/TestSuite.h>
#include "MantidHistogramData/Histogram.h"
#include "MantidHistogramData/HistogramIterator.h"
#include "MantidHistogramData/LinearGenerator.h"
using Mantid::HistogramData::BinEdges;
using Mantid::HistogramData::Counts;
using Mantid::HistogramData::CountStandardDeviations;
using Mantid::HistogramData::CountVariances;
using Mantid::HistogramData::Frequencies;
using Mantid::HistogramData::FrequencyStandardDeviations;
using Mantid::HistogramData::FrequencyVariances;
using Mantid::HistogramData::getHistogramXMode;
using Mantid::HistogramData::Histogram;
using Mantid::HistogramData::HistogramE;
using Mantid::HistogramData::HistogramX;
using Mantid::HistogramData::HistogramY;
using Mantid::HistogramData::LinearGenerator;
using Mantid::HistogramData::Points;
using Mantid::HistogramData::PointStandardDeviations;
class HistogramTest : 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 HistogramTest *createSuite() { return new HistogramTest(); }
static void destroySuite(HistogramTest *suite) { delete suite; }
void test_construction_Points_Counts() {
TS_ASSERT_THROWS_NOTHING(Histogram hist(Histogram::XMode::Points, Histogram::YMode::Counts));
}
void test_construction_BinEdges_Counts() {
TS_ASSERT_THROWS_NOTHING(Histogram hist(Histogram::XMode::BinEdges, Histogram::YMode::Counts));
}
void test_construction_Points_Frequencies() {
TS_ASSERT_THROWS_NOTHING(Histogram hist(Histogram::XMode::Points, Histogram::YMode::Frequencies));
}
void test_construction_BinEdges_Frequencies() {
TS_ASSERT_THROWS_NOTHING(Histogram hist(Histogram::XMode::BinEdges, Histogram::YMode::Frequencies));
}
void test_construct_from_Points() {
TS_ASSERT_THROWS_NOTHING(Histogram src(Points(0)));
TS_ASSERT_THROWS_NOTHING(Histogram src(Points{0.1, 0.2, 0.4}));
}
void test_construct_from_BinEdges() {
TS_ASSERT_THROWS_NOTHING(Histogram src(BinEdges(0)));
TS_ASSERT_THROWS_NOTHING(Histogram src(BinEdges{0.1, 0.2, 0.4}));
}
void test_construct_from_invalid_BinEdges() {
BinEdges binEdges(1);
TS_ASSERT_THROWS(Histogram{binEdges}, const std::logic_error &);
}
void test_construct_Points_Counts() {
TS_ASSERT_THROWS_NOTHING(Histogram src(Points{0.1, 0.2, 0.4}, Counts{1, 2, 4}));
}
void test_construct_Points_Counts_CountVariances() {
TS_ASSERT_THROWS_NOTHING(Histogram src(Points{1.0, 2.0}, Counts(2), CountVariances(2)));
}
void test_construct_Points_null_Counts_CountVariances() {
TS_ASSERT_THROWS_NOTHING(Histogram src(Points{1.0, 2.0}, Counts(), CountVariances()));
}
void test_construct_values_size_mismatch() {
TS_ASSERT_THROWS(Histogram(Points(1), Counts(2)), const std::logic_error &);
TS_ASSERT_THROWS(Histogram(BinEdges{1.0, 2.0}, Counts(2)), const std::logic_error &);
TS_ASSERT_THROWS(Histogram(Points(1), Frequencies(2)), const std::logic_error &);
TS_ASSERT_THROWS(Histogram(BinEdges{1.0, 2.0}, Frequencies(2)), const std::logic_error &);
}
void test_construct_values_uncertainties_size_mismatch() {
TS_ASSERT_THROWS(Histogram(Points{1.0, 2.0}, Counts(2), CountVariances(1)), const std::logic_error &);
TS_ASSERT_THROWS(Histogram(Points{1.0, 2.0}, Frequencies(2), FrequencyVariances(1)), const std::logic_error &);
}
void test_construct_null_values_but_uncertainties_fail() {
TS_ASSERT_THROWS(Histogram(Points{1.0, 2.0}, Counts(), CountVariances(2)), const std::logic_error &);
}
void test_construct_Counts_automatic_errors() {
Histogram histogram(BinEdges{1.0, 2.0, 3.0}, Counts{4.0, 9.0});
TS_ASSERT(histogram.sharedE());
TS_ASSERT_EQUALS(histogram.e()[0], 2.0);
TS_ASSERT_EQUALS(histogram.e()[1], 3.0);
}
void test_copy_constructor() {
Histogram src(Points{0.1, 0.2, 0.4});
Histogram dest(src);
TS_ASSERT(src.points());
auto points = dest.points();
TS_ASSERT(points);
TS_ASSERT_EQUALS(points.size(), 3);
TS_ASSERT_EQUALS(points[0], 0.1);
TS_ASSERT_EQUALS(points[1], 0.2);
TS_ASSERT_EQUALS(points[2], 0.4);
}
void test_move_constructor() {
Histogram src(Points{0.1, 0.2, 0.4});
Histogram dest(std::move(src));
TS_ASSERT(!src.points());
TS_ASSERT(dest.points());
}
void test_copy_assignment() {
Histogram src(Points{0.1, 0.2, 0.4});
Histogram dest(Histogram::XMode::BinEdges, Histogram::YMode::Counts);
TS_ASSERT_EQUALS(dest.xMode(), Histogram::XMode::BinEdges);
dest = src;
TS_ASSERT(src.points());
TS_ASSERT_EQUALS(dest.xMode(), Histogram::XMode::Points);
auto points = dest.points();
TS_ASSERT(points);
TS_ASSERT_EQUALS(points.size(), 3);
TS_ASSERT_EQUALS(points[0], 0.1);
TS_ASSERT_EQUALS(points[1], 0.2);
TS_ASSERT_EQUALS(points[2], 0.4);
}
void test_move_assignment() {
Histogram src(Points{0.1, 0.2, 0.4});
Histogram dest(Histogram::XMode::BinEdges, Histogram::YMode::Counts);
TS_ASSERT_EQUALS(dest.xMode(), Histogram::XMode::BinEdges);
dest = std::move(src);
TS_ASSERT(!src.points());
TS_ASSERT(dest.points());
TS_ASSERT_EQUALS(dest.xMode(), Histogram::XMode::Points);
}
void test_size() {
TS_ASSERT_EQUALS(Histogram(BinEdges(0)).size(), 0);
TS_ASSERT_EQUALS(Histogram(BinEdges(2)).size(), 1);
TS_ASSERT_EQUALS(Histogram(BinEdges(3)).size(), 2);
TS_ASSERT_EQUALS(Histogram(Points(0)).size(), 0);
TS_ASSERT_EQUALS(Histogram(Points(1)).size(), 1);
TS_ASSERT_EQUALS(Histogram(Points(2)).size(), 2);
}
void test_resize_point_data() {
Histogram histogram(Points(3), Counts(3));
histogram.resize(2);
TS_ASSERT_EQUALS(histogram.size(), 2);
TS_ASSERT_EQUALS(histogram.x().size(), 2);
TS_ASSERT_EQUALS(histogram.y().size(), 2);
histogram.resize(1);
TS_ASSERT_EQUALS(histogram.size(), 1);
TS_ASSERT_EQUALS(histogram.x().size(), 1);
TS_ASSERT_EQUALS(histogram.y().size(), 1);
histogram.resize(0);
TS_ASSERT_EQUALS(histogram.size(), 0);
TS_ASSERT_EQUALS(histogram.x().size(), 0);
TS_ASSERT_EQUALS(histogram.y().size(), 0);
}
void test_resize_histogram() {
Histogram histogram(BinEdges(4), Counts(3));
histogram.resize(2);
TS_ASSERT_EQUALS(histogram.size(), 2);
TS_ASSERT_EQUALS(histogram.x().size(), 3);
TS_ASSERT_EQUALS(histogram.y().size(), 2);
histogram.resize(1);
TS_ASSERT_EQUALS(histogram.size(), 1);
TS_ASSERT_EQUALS(histogram.x().size(), 2);
TS_ASSERT_EQUALS(histogram.y().size(), 1);
histogram.resize(0);
TS_ASSERT_EQUALS(histogram.size(), 0);
TS_ASSERT_EQUALS(histogram.x().size(), 0);
TS_ASSERT_EQUALS(histogram.y().size(), 0);
}
void test_xMode() {
Histogram hist1(Histogram::XMode::Points, Histogram::YMode::Counts);
TS_ASSERT_EQUALS(hist1.xMode(), Histogram::XMode::Points);
Histogram hist2(Histogram::XMode::BinEdges, Histogram::YMode::Counts);
TS_ASSERT_EQUALS(hist2.xMode(), Histogram::XMode::BinEdges);
}
void test_getHistogramXMode() {
TS_ASSERT_EQUALS(getHistogramXMode(0, 0), Histogram::XMode::Points);
TS_ASSERT_EQUALS(getHistogramXMode(1, 1), Histogram::XMode::Points);
TS_ASSERT_EQUALS(getHistogramXMode(1, 0), Histogram::XMode::BinEdges);
TS_ASSERT_EQUALS(getHistogramXMode(2, 1), Histogram::XMode::BinEdges);
TS_ASSERT_THROWS(getHistogramXMode(2, 0), const std::logic_error &);
TS_ASSERT_THROWS(getHistogramXMode(3, 1), const std::logic_error &);
TS_ASSERT_THROWS(getHistogramXMode(0, 1), const std::logic_error &);
}
void test_assignment() {
const Histogram src(Points(1));
Histogram dest(Points(1));
TS_ASSERT_THROWS_NOTHING(dest = src);
TS_ASSERT_EQUALS(&dest.x()[0], &src.x()[0]);
}
void test_assignment_mutating() {
const Histogram src(Points(1));
Histogram dest(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(dest = src);
TS_ASSERT_EQUALS(&dest.x()[0], &src.x()[0]);
}
void test_assignment_size_change() {
Histogram src1(Points(1));
Histogram dest1(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(dest1 = src1);
Histogram src2(Points(1));
Histogram dest2(BinEdges{1.0, 2.0, 3.0});
TS_ASSERT_THROWS_NOTHING(dest2 = src2);
Histogram src3(BinEdges{1.0, 2.0});
Histogram dest3(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(dest3 = src3);
Histogram src4(BinEdges{1.0, 2.0});
Histogram dest4(BinEdges{1.0, 2.0, 3.0});
TS_ASSERT_THROWS_NOTHING(dest4 = src4);
}
void test_points_from_edges() {
BinEdges binEdges{0.1, 0.2, 0.4};
const Histogram hist(binEdges);
const auto points = hist.points();
TS_ASSERT_DIFFERS(&points[0], &hist.x()[0]);
TS_ASSERT_EQUALS(points.size(), 2);
TS_ASSERT_DELTA(points[0], 0.15, 1e-14);
TS_ASSERT_DELTA(points[1], 0.3, 1e-14);
}
void test_points_from_points() {
const Histogram hist(Points{0.1, 0.2, 0.4});
const auto points = hist.points();
TS_ASSERT_EQUALS(&points[0], &hist.x()[0]);
}
void test_no_counts_and_frequencies() {
const Histogram hist(BinEdges{0.1, 0.2, 0.4});
TS_ASSERT(!hist.counts());
TS_ASSERT(!hist.countVariances());
TS_ASSERT(!hist.countStandardDeviations());
TS_ASSERT(!hist.frequencies());
TS_ASSERT(!hist.frequencyVariances());
TS_ASSERT(!hist.frequencyStandardDeviations());
}
void test_counts() {
Histogram hist(BinEdges{0.1, 0.2, 0.4});
hist.setCounts(Counts{10, 100});
TS_ASSERT(hist.counts());
TS_ASSERT_EQUALS(hist.counts().size(), 2);
TS_ASSERT_EQUALS(hist.counts()[0], 10);
TS_ASSERT_EQUALS(hist.counts()[1], 100);
}
void test_counts_references_internal_data() {
Histogram hist(BinEdges{0.1, 0.2, 0.4});
hist.setCounts(Counts{10, 100});
TS_ASSERT_EQUALS(&hist.counts()[0], &hist.counts()[0]);
}
void test_frequencies() {
Histogram hist(BinEdges{0.1, 0.2, 0.4});
hist.setCounts(Counts{10, 100});
TS_ASSERT(hist.frequencies());
TS_ASSERT_EQUALS(hist.frequencies().size(), 2);
TS_ASSERT_EQUALS(hist.frequencies()[0], 100.0);
TS_ASSERT_EQUALS(hist.frequencies()[1], 500.0);
}
void test_frequencies_does_not_reference_internal_data() {
Histogram hist(BinEdges{0.1, 0.2, 0.4});
hist.setCounts(Counts{10, 100});
TS_ASSERT_DIFFERS(&hist.frequencies()[0], &hist.frequencies()[0]);
}
void test_setPoints_from_vector() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h1.setPoints(std::vector<double>{0.1, 0.2}));
TS_ASSERT_EQUALS(h1.x().size(), 2);
TS_ASSERT_EQUALS(h1.x()[0], 0.1);
TS_ASSERT_EQUALS(h1.x()[1], 0.2);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h2.setPoints(std::vector<double>{0.1}));
TS_ASSERT_EQUALS(h2.x().size(), 1);
TS_ASSERT_EQUALS(h2.x()[0], 0.1);
}
void test_setPoints_from_Points() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h1.setPoints(Points{0.1, 0.2}));
TS_ASSERT_EQUALS(h1.x().size(), 2);
TS_ASSERT_EQUALS(h1.x()[0], 0.1);
TS_ASSERT_EQUALS(h1.x()[1], 0.2);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h2.setPoints(Points{0.1}));
TS_ASSERT_EQUALS(h2.x().size(), 1);
TS_ASSERT_EQUALS(h2.x()[0], 0.1);
}
void test_setPoints_from_BinEdges() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h1.setPoints(BinEdges{0.1, 0.2, 0.4}));
TS_ASSERT_EQUALS(h1.x().size(), 2);
TS_ASSERT_DELTA(h1.x()[0], 0.15, 1e-14);
TS_ASSERT_DELTA(h1.x()[1], 0.3, 1e-14);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h2.setPoints(BinEdges{0.1, 0.2}));
TS_ASSERT_EQUALS(h2.x().size(), 1);
TS_ASSERT_DELTA(h2.x()[0], 0.15, 1e-14);
}
void test_setPoints_degenerate() {
Histogram h1(Points(0));
TS_ASSERT_THROWS_NOTHING(h1.setPoints(std::vector<double>(0)));
TS_ASSERT_EQUALS(h1.x().size(), 0);
TS_ASSERT_THROWS_NOTHING(h1.setPoints(Points(0)));
TS_ASSERT_EQUALS(h1.x().size(), 0);
TS_ASSERT_THROWS_NOTHING(h1.setPoints(BinEdges(0)));
TS_ASSERT_EQUALS(h1.x().size(), 0);
Histogram h2(BinEdges(0));
TS_ASSERT_THROWS_NOTHING(h2.setPoints(std::vector<double>(0)));
TS_ASSERT_EQUALS(h2.x().size(), 0);
TS_ASSERT_THROWS_NOTHING(h2.setPoints(Points(0)));
TS_ASSERT_EQUALS(h2.x().size(), 0);
TS_ASSERT_THROWS_NOTHING(h2.setPoints(BinEdges(0)));
TS_ASSERT_EQUALS(h2.x().size(), 0);
}
void test_setPoints_size_mismatch() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS(h1.setPoints(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setPoints(std::vector<double>{1.0, 2.0, 3.0}), const std::logic_error &);
TS_ASSERT_THROWS(h1.setPoints(Points(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setPoints(Points{1.0, 2.0, 3.0}), const std::logic_error &);
TS_ASSERT_THROWS(h1.setPoints(BinEdges{1.0, 2.0}), const std::logic_error &);
TS_ASSERT_THROWS(h1.setPoints(BinEdges{1.0, 2.0, 3.0, 4.0}), const std::logic_error &);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS(h2.setPoints(std::vector<double>(0)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setPoints(std::vector<double>{1.0, 2.0}), const std::logic_error &);
TS_ASSERT_THROWS(h2.setPoints(Points(0)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setPoints(Points{1.0, 2.0}), const std::logic_error &);
TS_ASSERT_THROWS(h2.setPoints(BinEdges(1)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setPoints(BinEdges{1.0, 2.0, 3.0}), const std::logic_error &);
}
void test_setPoints_size_mismatch_degenerate() {
Histogram h1(Points(0));
TS_ASSERT_THROWS(h1.setPoints(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setPoints(Points(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setPoints(BinEdges(1)), const std::logic_error &);
Histogram h2(BinEdges(0));
TS_ASSERT_THROWS(h2.setPoints(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setPoints(Points(1)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setPoints(BinEdges(1)), const std::logic_error &);
}
void test_setPoints_self_assignment() {
Histogram h(Points(0));
auto &x = h.x();
auto old_address = &x;
h.setPoints(x);
TS_ASSERT_EQUALS(&h.x(), old_address);
}
void test_setPoints_legacy_self_assignment() {
Histogram h(Points(0));
auto &x = h.readX();
auto old_address = &x;
h.setPoints(x);
TS_ASSERT_EQUALS(&h.readX(), old_address);
}
void test_setPoints_self_assignment_with_size_mismatch() {
Histogram h(BinEdges{1.0, 2.0});
auto &x = h.x();
// This test makes sure that size mismatch takes precedence over the
// self-assignment check. x is bin edges, setting it as points should fail.
TS_ASSERT_THROWS(h.setPoints(x), const std::logic_error &);
}
void test_setPoints_keepsDxStorageMode() {
Histogram hist(BinEdges{1.0, 2.0, 3.0});
auto dx = {1.0, 2.0};
hist.setPointStandardDeviations(dx);
hist.setPoints(Points{1.0, 2.0});
TS_ASSERT_EQUALS(hist.dx().size(), 2);
TS_ASSERT_EQUALS(hist.dx()[0], 1.0);
TS_ASSERT_EQUALS(hist.dx()[1], 2.0);
}
void test_edges_from_edges() {
const Histogram hist(BinEdges{0.1, 0.2, 0.4});
const auto edges = hist.binEdges();
TS_ASSERT_EQUALS(&edges[0], &hist.x()[0]);
TS_ASSERT_EQUALS(edges.size(), 3);
}
void test_edges_from_points() {
const Histogram hist(Points{0.1, 0.2, 0.4});
const auto edges = hist.binEdges();
TS_ASSERT_DIFFERS(&edges[0], &hist.x()[0]);
TS_ASSERT_EQUALS(edges.size(), 4);
}
void test_setBinEdges() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h1.setBinEdges(std::vector<double>{1.0, 2.0, 3.0}));
TS_ASSERT_THROWS_NOTHING(h1.setBinEdges(Points{1.0, 2.0}));
TS_ASSERT_THROWS_NOTHING(h1.setBinEdges(BinEdges{1.0, 2.0, 3.0}));
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h2.setBinEdges(std::vector<double>{1.0, 2.0}));
TS_ASSERT_THROWS_NOTHING(h2.setBinEdges(Points(1)));
TS_ASSERT_THROWS_NOTHING(h2.setBinEdges(BinEdges{1.0, 2.0}));
}
void test_setBinEdges_from_vector() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h1.setBinEdges(std::vector<double>{0.1, 0.2, 0.4}));
TS_ASSERT_EQUALS(h1.x().size(), 3);
TS_ASSERT_EQUALS(h1.x()[0], 0.1);
TS_ASSERT_EQUALS(h1.x()[1], 0.2);
TS_ASSERT_EQUALS(h1.x()[2], 0.4);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h2.setBinEdges(std::vector<double>{0.1, 0.2}));
TS_ASSERT_EQUALS(h2.x().size(), 2);
TS_ASSERT_EQUALS(h2.x()[0], 0.1);
TS_ASSERT_EQUALS(h2.x()[1], 0.2);
}
void test_setBinEdges_from_Points() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h1.setBinEdges(Points{0.1, 0.3}));
TS_ASSERT_EQUALS(h1.x().size(), 3);
TS_ASSERT_DELTA(h1.x()[0], 0.0, 1e-14);
TS_ASSERT_DELTA(h1.x()[1], 0.2, 1e-14);
TS_ASSERT_DELTA(h1.x()[2], 0.4, 1e-14);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h2.setBinEdges(Points{1.0}));
TS_ASSERT_EQUALS(h2.x().size(), 2);
TS_ASSERT_DELTA(h2.x()[0], 0.5, 1e-14);
TS_ASSERT_DELTA(h2.x()[1], 1.5, 1e-14);
}
void test_setBinEdges_from_BinEdges() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h1.setBinEdges(BinEdges{0.1, 0.2, 0.4}));
TS_ASSERT_EQUALS(h1.x().size(), 3);
TS_ASSERT_EQUALS(h1.x()[0], 0.1);
TS_ASSERT_EQUALS(h1.x()[1], 0.2);
TS_ASSERT_EQUALS(h1.x()[2], 0.4);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h2.setBinEdges(BinEdges{0.1, 0.2}));
TS_ASSERT_EQUALS(h2.x().size(), 2);
TS_ASSERT_EQUALS(h2.x()[0], 0.1);
TS_ASSERT_EQUALS(h2.x()[1], 0.2);
}
void test_setBinEdges_degenerate() {
Histogram h1(Points(0));
TS_ASSERT_THROWS_NOTHING(h1.setBinEdges(std::vector<double>(0)));
TS_ASSERT_EQUALS(h1.x().size(), 0);
TS_ASSERT_THROWS_NOTHING(h1.setBinEdges(Points(0)));
TS_ASSERT_EQUALS(h1.x().size(), 0);
TS_ASSERT_THROWS_NOTHING(h1.setBinEdges(BinEdges(0)));
TS_ASSERT_EQUALS(h1.x().size(), 0);
Histogram h2(BinEdges(0));
TS_ASSERT_THROWS_NOTHING(h2.setBinEdges(std::vector<double>(0)));
TS_ASSERT_EQUALS(h2.x().size(), 0);
TS_ASSERT_THROWS_NOTHING(h2.setBinEdges(Points(0)));
TS_ASSERT_EQUALS(h2.x().size(), 0);
TS_ASSERT_THROWS_NOTHING(h2.setBinEdges(BinEdges(0)));
TS_ASSERT_EQUALS(h2.x().size(), 0);
}
void test_setBinEdges_size_mismatch() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS(h1.setBinEdges(std::vector<double>{1.0, 2.0}), const std::logic_error &);
TS_ASSERT_THROWS(h1.setBinEdges(std::vector<double>{1.0, 2.0, 3.0, 4.0}), const std::logic_error &);
TS_ASSERT_THROWS(h1.setBinEdges(Points(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setBinEdges(Points{1.0, 2.0, 3.0}), const std::logic_error &);
TS_ASSERT_THROWS(h1.setBinEdges(BinEdges{1.0, 2.0}), const std::logic_error &);
TS_ASSERT_THROWS(h1.setBinEdges(BinEdges{1.0, 2.0, 3.0, 4.0}), const std::logic_error &);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS(h2.setBinEdges(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setBinEdges(std::vector<double>{1.0, 2.0, 3.0}), const std::logic_error &);
TS_ASSERT_THROWS(h2.setBinEdges(Points(0)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setBinEdges(Points{1.0, 2.0}), const std::logic_error &);
TS_ASSERT_THROWS(h2.setBinEdges(BinEdges(1)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setBinEdges(BinEdges{1.0, 2.0, 3.0}), const std::logic_error &);
}
void test_setBinEdges_size_mismatch_degenerate() {
Histogram h1(Points(0));
TS_ASSERT_THROWS(h1.setBinEdges(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setBinEdges(Points(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setBinEdges(BinEdges(1)), const std::logic_error &);
Histogram h2(BinEdges(0));
TS_ASSERT_THROWS(h2.setBinEdges(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setBinEdges(Points(1)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setBinEdges(BinEdges(1)), const std::logic_error &);
}
void test_setBinEdges_self_assignment() {
Histogram h(BinEdges(0));
auto &x = h.x();
auto old_address = &x;
h.setBinEdges(x);
TS_ASSERT_EQUALS(&h.x(), old_address);
}
void test_setBinEdges_legacy_self_assignment() {
Histogram h(BinEdges(0));
auto &x = h.readX();
auto old_address = &x;
h.setBinEdges(x);
TS_ASSERT_EQUALS(&h.readX(), old_address);
}
void test_setBinEdges_self_assignment_with_size_mismatch() {
Histogram h(Points{1.0, 2.0});
auto &x = h.x();
// This test makes sure that size mismatch takes precedence over the
// self-assignment check. x is points, setting it as bin edges should fail.
TS_ASSERT_THROWS(h.setBinEdges(x), const std::logic_error &);
}
void test_setBinEdges_keepsDxStorageMode() {
Histogram hist(Points{1.0, 2.0});
auto dx = {1.0, 2.0};
hist.setPointStandardDeviations(dx);
hist.setBinEdges(BinEdges{1.0, 2.0, 3.0});
TS_ASSERT_EQUALS(hist.dx().size(), 2);
TS_ASSERT_EQUALS(hist.dx()[0], 1.0);
TS_ASSERT_EQUALS(hist.dx()[1], 2.0);
}
void test_setCounts_size_mismatch() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS(h1.setCounts(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setCounts(std::vector<double>(3)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setCounts(Counts(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setCounts(Counts(3)), const std::logic_error &);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS(h2.setCounts(std::vector<double>(0)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setCounts(std::vector<double>(2)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setCounts(Counts(0)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setCounts(Counts(2)), const std::logic_error &);
}
void test_setCounts_size_mismatch_degenerate() {
Histogram h1(Points(0));
TS_ASSERT_THROWS(h1.setCounts(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setCounts(Counts(1)), const std::logic_error &);
Histogram h2(BinEdges(0));
TS_ASSERT_THROWS(h2.setCounts(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setCounts(Counts(1)), const std::logic_error &);
}
void test_setCounts_self_assignment() {
Histogram h(Points(0));
h.setCounts(0);
auto &y = h.y();
auto old_address = &y;
h.setCounts(y);
TS_ASSERT_EQUALS(&h.y(), old_address);
}
void test_setCounts_legacy_self_assignment() {
Histogram h(Points(0));
h.setCounts(0);
auto &y = h.readY();
auto old_address = &y;
h.setPoints(y);
TS_ASSERT_EQUALS(&h.readY(), old_address);
}
void test_setFrequencies_size_mismatch() {
Histogram h1(Points{1.0, 2.0});
TS_ASSERT_THROWS(h1.setFrequencies(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setFrequencies(std::vector<double>(3)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setFrequencies(Frequencies(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setFrequencies(Frequencies(3)), const std::logic_error &);
Histogram h2(BinEdges{1.0, 2.0});
TS_ASSERT_THROWS(h2.setFrequencies(std::vector<double>(0)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setFrequencies(std::vector<double>(2)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setFrequencies(Frequencies(0)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setFrequencies(Frequencies(2)), const std::logic_error &);
}
void test_setFrequencies_size_mismatch_degenerate() {
Histogram h1(Points(0));
TS_ASSERT_THROWS(h1.setFrequencies(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h1.setFrequencies(Frequencies(1)), const std::logic_error &);
Histogram h2(BinEdges(0));
TS_ASSERT_THROWS(h2.setFrequencies(std::vector<double>(1)), const std::logic_error &);
TS_ASSERT_THROWS(h2.setFrequencies(Frequencies(1)), const std::logic_error &);
}
void test_setFrequencies_self_assignment() {
Histogram h(Points(0));
h.setFrequencies(0);
auto &y = h.y();
auto old_address = &y;
h.setFrequencies(y);
TS_ASSERT_EQUALS(&h.y(), old_address);
}
void test_setFrequencies_legacy_self_assignment() {
Histogram h(Points(0));
h.setFrequencies(0);
auto &y = h.readY();
auto old_address = &y;
h.setFrequencies(y);
TS_ASSERT_EQUALS(&h.readY(), old_address);
}
void test_setCountVariances() {
Histogram h(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h.setCountVariances(2));
}
void test_setCountStandardDeviations() {
Histogram h(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h.setCountStandardDeviations(2));
}
void test_setFrequenciesDataValid() {
Histogram h(BinEdges{1, 2, 3});
std::vector<double> freqs(2, 0.36);
h.setFrequencies(freqs);
TS_ASSERT_EQUALS(freqs, h.y().rawData());
}
void test_setFrequencyVariances() {
Histogram h(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h.setFrequencyVariances(2));
}
void test_setFrequencyVariancesDataValid() {
Histogram h(BinEdges{1, 2, 3});
std::vector<double> freqVars(2, 100);
std::vector<double> freqStdDevs(2, 10);
h.setFrequencyVariances(freqVars);
TS_ASSERT_EQUALS(freqStdDevs, h.e().rawData());
}
void test_setFrequencyStandardDeviations() {
Histogram h(Points{1.0, 2.0});
TS_ASSERT_THROWS_NOTHING(h.setFrequencyStandardDeviations(2));
}
void test_setFrequencyStandardDeviationsDataValid() {
Histogram h(BinEdges{1, 2, 3});
std::vector<double> freqStdDevs(2, 0.11);
h.setFrequencyStandardDeviations(freqStdDevs);
TS_ASSERT_EQUALS(freqStdDevs, h.e().rawData());
}
void test_setCountVariances_size_mismatch() {
Histogram h(Points{1.0, 2.0});
TS_ASSERT_THROWS(h.setCountVariances(1), const std::logic_error &);
TS_ASSERT_THROWS(h.setCountVariances(3), const std::logic_error &);
}
void test_setCountStandardDeviations_size_mismatch() {
Histogram h(Points{1.0, 2.0});
TS_ASSERT_THROWS(h.setCountStandardDeviations(1), const std::logic_error &);
TS_ASSERT_THROWS(h.setCountStandardDeviations(3), const std::logic_error &);
}
void test_setFrequencyVariances_size_mismatch() {
Histogram h(Points{1.0, 2.0});
TS_ASSERT_THROWS(h.setFrequencyVariances(1), const std::logic_error &);
TS_ASSERT_THROWS(h.setFrequencyVariances(3), const std::logic_error &);
}
void test_setFrequencyStandardDeviations_size_mismatch() {
Histogram h(Points{1.0, 2.0});
TS_ASSERT_THROWS(h.setFrequencyStandardDeviations(1), const std::logic_error &);
TS_ASSERT_THROWS(h.setFrequencyStandardDeviations(3), const std::logic_error &);
}
void test_error_setter_self_assignment() {
Histogram h(Points{1.0, 2.0});
h.setCountVariances(2);
auto &e = h.e();
auto old_address = &e;
// e is always count standard deviations, self assignment as variances or
// frequencies should fail unless we are setting count standard deviations.
TS_ASSERT_THROWS(h.setCountVariances(e), const std::logic_error &);
TS_ASSERT_THROWS(h.setFrequencyVariances(e), const std::logic_error &);
TS_ASSERT_THROWS(h.setFrequencyStandardDeviations(e), const std::logic_error &);
TS_ASSERT_THROWS_NOTHING(h.setCountStandardDeviations(e));
TS_ASSERT_EQUALS(&h.e(), old_address);
}
void test_x() {
Histogram hist(Points({0.1, 0.2, 0.4}));
TS_ASSERT_EQUALS(hist.x()[0], 0.1);
TS_ASSERT_EQUALS(hist.x()[1], 0.2);
TS_ASSERT_EQUALS(hist.x()[2], 0.4);
}
void test_x_references_internal_data() {
Histogram hist(Points(0));
auto copy(hist);
TS_ASSERT_EQUALS(&hist.x(), ©.x());
}
void test_mutableX() {
Histogram hist(Points({0.1, 0.2, 0.4}));
TS_ASSERT_EQUALS(hist.mutableX()[0], 0.1);
TS_ASSERT_EQUALS(hist.mutableX()[1], 0.2);
TS_ASSERT_EQUALS(hist.mutableX()[2], 0.4);
}
void test_mutableX_triggers_copy() {
Histogram hist(Points(0));
auto copy(hist);
TS_ASSERT_DIFFERS(&hist.x(), ©.mutableX());
}
void test_x_references_same_data_as_binEdges() {
Histogram hist(BinEdges(0));
TS_ASSERT_EQUALS(&hist.x(), &hist.binEdges().data());
TS_ASSERT_DIFFERS(&hist.x(), &hist.points().data());
}
void test_x_references_same_data_as_points() {
Histogram hist(Points(0));
TS_ASSERT_DIFFERS(&hist.x(), &hist.binEdges().data());
TS_ASSERT_EQUALS(&hist.x(), &hist.points().data());
}
void test_sharedX() {
auto data = Mantid::Kernel::make_cow<HistogramX>(0);
Histogram hist{BinEdges(data)};
TS_ASSERT_EQUALS(hist.sharedX(), data);
}
void test_setSharedX() {
auto data1 = Mantid::Kernel::make_cow<HistogramX>(0);
auto data2 = Mantid::Kernel::make_cow<HistogramX>(0);
Histogram hist{BinEdges(data1)};
TS_ASSERT_EQUALS(hist.sharedX(), data1);
TS_ASSERT_THROWS_NOTHING(hist.setSharedX(data2));
TS_ASSERT_DIFFERS(hist.sharedX(), data1);
TS_ASSERT_EQUALS(hist.sharedX(), data2);
}
void test_setSharedX_size_mismatch() {
auto data1 = Mantid::Kernel::make_cow<HistogramX>(0);
auto tmp = {1.0, 2.0};
auto data2 = Mantid::Kernel::make_cow<HistogramX>(tmp);
Histogram hist{BinEdges(data1)};
TS_ASSERT_THROWS(hist.setSharedX(data2), const std::logic_error &);
}
void test_setSharedX_catches_misuse() {
BinEdges edges{1.0, 2.0};
Histogram hist(edges);
auto points = hist.points();
TS_ASSERT_THROWS(hist.setSharedX(points.cowData()), const std::logic_error &);
}
void test_y() {
Histogram hist(Points{1.0, 2.0, 3.0});
hist.setCounts(Counts{0.1, 0.2, 0.4});
TS_ASSERT_EQUALS(hist.y()[0], 0.1);
TS_ASSERT_EQUALS(hist.y()[1], 0.2);
TS_ASSERT_EQUALS(hist.y()[2], 0.4);
}
void test_y_references_internal_data() {
Histogram hist(Points(0));
hist.setCounts(0);
auto copy(hist);
TS_ASSERT_EQUALS(&hist.y(), ©.y());
}
void test_mutableY() {
Histogram hist(Points{1.0, 2.0, 3.0});
hist.setCounts(Counts{0.1, 0.2, 0.4});
TS_ASSERT_EQUALS(hist.mutableY()[0], 0.1);
TS_ASSERT_EQUALS(hist.mutableY()[1], 0.2);
TS_ASSERT_EQUALS(hist.mutableY()[2], 0.4);
}
void test_mutableY_triggers_copy() {
Histogram hist(Points(0));
hist.setCounts(0);
auto copy(hist);
TS_ASSERT_DIFFERS(&hist.y(), ©.mutableY());
}
void test_y_references_same_data_as_counts() {
Histogram hist(Points(0));
hist.setCounts(0);
TS_ASSERT_EQUALS(&hist.y(), &hist.counts().data());
TS_ASSERT_DIFFERS(&hist.y(), &hist.frequencies().data());
}
void test_sharedY() {
auto data = Mantid::Kernel::make_cow<HistogramY>(0);
Histogram hist{BinEdges(0)};
hist.setCounts(data);
TS_ASSERT_EQUALS(hist.sharedY(), data);
}
void test_setSharedY() {
auto data1 = Mantid::Kernel::make_cow<HistogramY>(0);
auto data2 = Mantid::Kernel::make_cow<HistogramY>(0);
Histogram hist{BinEdges(0)};
hist.setCounts(data1);
TS_ASSERT_EQUALS(hist.sharedY(), data1);
TS_ASSERT_THROWS_NOTHING(hist.setSharedY(data2));
TS_ASSERT_DIFFERS(hist.sharedY(), data1);
TS_ASSERT_EQUALS(hist.sharedY(), data2);
}
void test_setSharedY_size_mismatch() {
auto data1 = Mantid::Kernel::make_cow<HistogramY>(0);
auto data2 = Mantid::Kernel::make_cow<HistogramY>(2);
Histogram hist{BinEdges(0)};
hist.setCounts(data1);
TS_ASSERT_THROWS(hist.setSharedY(data2), const std::logic_error &);
}
void test_e() {
Histogram hist(Points{1.0, 2.0, 3.0});
hist.setCountStandardDeviations(CountStandardDeviations{0.1, 0.2, 0.4});
TS_ASSERT_EQUALS(hist.e()[0], 0.1);
TS_ASSERT_EQUALS(hist.e()[1], 0.2);
TS_ASSERT_EQUALS(hist.e()[2], 0.4);
}
void test_e_references_internal_data() {
Histogram hist(Points(0));
hist.setCountStandardDeviations(0);
auto copy(hist);
TS_ASSERT_EQUALS(&hist.e(), ©.e());
}
void test_mutableE() {
Histogram hist(Points{1.0, 2.0, 3.0});
hist.setCountStandardDeviations(CountStandardDeviations{0.1, 0.2, 0.4});
TS_ASSERT_EQUALS(hist.mutableE()[0], 0.1);
TS_ASSERT_EQUALS(hist.mutableE()[1], 0.2);
TS_ASSERT_EQUALS(hist.mutableE()[2], 0.4);
}
void test_mutableE_triggers_copy() {
Histogram hist(Points(0));
hist.setCountStandardDeviations(0);
auto copy(hist);
TS_ASSERT_DIFFERS(&hist.e(), ©.mutableE());
}
void test_e_references_same_data_as_counts() {
Histogram hist(Points(0));
hist.setCountStandardDeviations(0);
TS_ASSERT_EQUALS(&hist.e(), &hist.countStandardDeviations().data());
TS_ASSERT_DIFFERS(&hist.e(), &hist.frequencyStandardDeviations().data());
}
void test_sharedE() {
auto data = Mantid::Kernel::make_cow<HistogramE>(0);
Histogram hist{BinEdges(0)};
hist.setCountStandardDeviations(data);
TS_ASSERT_EQUALS(hist.sharedE(), data);
}
void test_setSharedE() {
auto data1 = Mantid::Kernel::make_cow<HistogramE>(0);
auto data2 = Mantid::Kernel::make_cow<HistogramE>(0);
Histogram hist{BinEdges(0)};
hist.setCountStandardDeviations(data1);
TS_ASSERT_EQUALS(hist.sharedE(), data1);
TS_ASSERT_THROWS_NOTHING(hist.setSharedE(data2));
TS_ASSERT_DIFFERS(hist.sharedE(), data1);
TS_ASSERT_EQUALS(hist.sharedE(), data2);
}
void test_setSharedE_size_mismatch() {
auto data1 = Mantid::Kernel::make_cow<HistogramE>(0);
auto data2 = Mantid::Kernel::make_cow<HistogramE>(2);
Histogram hist{BinEdges(0)};
hist.setCountStandardDeviations(data1);
TS_ASSERT_THROWS(hist.setSharedE(data2), const std::logic_error &);
}
void test_setPointStandardDeviations_point_data() {
Histogram hist(Points(2));
TS_ASSERT_THROWS_NOTHING(hist.setPointStandardDeviations(std::vector<double>{1.0, 2.0}));
TS_ASSERT_EQUALS(hist.dx().size(), 2);
TS_ASSERT_EQUALS(hist.dx()[0], 1.0);
TS_ASSERT_EQUALS(hist.dx()[1], 2.0);
}
void test_setPointStandardDeviations_point_data_size_mismatch() {
Histogram hist(Points(2));
TS_ASSERT_THROWS(hist.setPointStandardDeviations(PointStandardDeviations(0)), const std::logic_error &);
TS_ASSERT_THROWS(hist.setPointStandardDeviations(PointStandardDeviations(1)), const std::logic_error &);
TS_ASSERT_THROWS(hist.setPointStandardDeviations(PointStandardDeviations(3)), const std::logic_error &);
}
void test_setPointStandardDeviations_histogram_data() {
Histogram hist(BinEdges(3));
TS_ASSERT_THROWS_NOTHING(hist.setPointStandardDeviations(std::vector<double>{1.0, 2.0}));
TS_ASSERT_EQUALS(hist.dx().size(), 2);
TS_ASSERT_EQUALS(hist.dx()[0], 1.0);
TS_ASSERT_EQUALS(hist.dx()[1], 2.0);
}
void test_setPointStandardDeviations_histogram_data_size_mismatch() {
Histogram hist(BinEdges(3));
TS_ASSERT_THROWS(hist.setPointStandardDeviations(PointStandardDeviations(0)), const std::logic_error &);
TS_ASSERT_THROWS(hist.setPointStandardDeviations(PointStandardDeviations(1)), const std::logic_error &);
TS_ASSERT_THROWS(hist.setPointStandardDeviations(PointStandardDeviations(3)), const std::logic_error &);
}
void test_setPointStandardDeviations_can_set_null() {
Histogram hist(Points(2));
hist.setPointStandardDeviations(2);
PointStandardDeviations null;
TS_ASSERT(hist.sharedDx());
TS_ASSERT_THROWS_NOTHING(hist.setPointStandardDeviations(null));
TS_ASSERT(!hist.sharedDx());
}
void test_setPointStandardDeviations_accepts_default_construction() {
Histogram hist(Points(2));
hist.setPointStandardDeviations(2);
TS_ASSERT(hist.sharedDx());
TS_ASSERT_THROWS_NOTHING(hist.setPointStandardDeviations());
TS_ASSERT(!hist.sharedDx());
}
void test_yMode() {
Histogram hist1(Histogram::XMode::Points, Histogram::YMode::Counts);
TS_ASSERT_EQUALS(hist1.yMode(), Histogram::YMode::Counts);
Histogram hist2(Histogram::XMode::Points, Histogram::YMode::Frequencies);
TS_ASSERT_EQUALS(hist2.yMode(), Histogram::YMode::Frequencies);
}
void test_yMode_Uninitialized() {
Histogram hist(Points(1));
TS_ASSERT_EQUALS(hist.yMode(), Histogram::YMode::Uninitialized);
}
void test_yMode_initialized_by_setCounts() {
Histogram h(Points(2));
h.setCounts(2);
TS_ASSERT_EQUALS(h.yMode(), Histogram::YMode::Counts);
}
void test_yMode_initialized_by_setCountStandardDeviations() {
Histogram h(Points(2));
h.setCountStandardDeviations(2);
TS_ASSERT_EQUALS(h.yMode(), Histogram::YMode::Counts);
}
void test_yMode_initialized_by_setCountVariances() {
Histogram h(Points(2));
h.setCountVariances(2);
TS_ASSERT_EQUALS(h.yMode(), Histogram::YMode::Counts);
}
void test_yMode_initialized_by_setFrequencies() {
Histogram h(Points(2));
h.setFrequencies(2);
TS_ASSERT_EQUALS(h.yMode(), Histogram::YMode::Frequencies);
}
void test_yMode_initialized_by_setFrequencyStandardDeviations() {
Histogram h(Points(2));
h.setFrequencyStandardDeviations(2);
TS_ASSERT_EQUALS(h.yMode(), Histogram::YMode::Frequencies);
}
void test_yMode_initialized_by_setFrequencyVariances() {
Histogram h(Points(2));
h.setFrequencyVariances(2);
TS_ASSERT_EQUALS(h.yMode(), Histogram::YMode::Frequencies);