Skip to content

Commit

Permalink
fix and test getBin
Browse files Browse the repository at this point in the history
  • Loading branch information
XzzX committed Feb 18, 2025
1 parent 48e7851 commit a059fd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mrmd/data/MultiHistogram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct MultiHistogram
*/
KOKKOS_INLINE_FUNCTION idx_t getBin(const real_t& val) const
{
auto bin = idx_c((val - min) * inverseBinSize);
auto bin = idx_c(std::floor((val - min) * inverseBinSize));
if (bin < 0) bin = -1;
if (bin >= numBins) bin = -1;
return bin;
Expand Down
9 changes: 9 additions & 0 deletions mrmd/data/MultiHistogram.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ namespace mrmd
namespace data
{

TEST(MultiHistogram, getBin)
{
MultiHistogram histogram("histogram", 0_r, 10_r, 10, 2);
EXPECT_EQ(histogram.getBin(-0.5_r), -1);
EXPECT_EQ(histogram.getBin(0.5_r), 0);
EXPECT_EQ(histogram.getBin(5.5_r), 5);
EXPECT_EQ(histogram.getBin(10.5_r), -1);
}

TEST(MultiHistogram, getBinPosition)
{
MultiHistogram histogram("histogram", 0_r, 10_r, 10, 2);
Expand Down

0 comments on commit a059fd4

Please sign in to comment.