Skip to content

Commit

Permalink
Fix issue #5
Browse files Browse the repository at this point in the history
Initialize prev_end with smallest possible value and then count upwards
  • Loading branch information
const-ae committed May 22, 2019
1 parent 42f1bdf commit 8b8320a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cluster_interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ IntegerVector cluster_interval(NumericVector starts, NumericVector ends, int max
// The implementation is inspired by the bedtools implementation:
// https://github.com/arq5x/bedtools2/blob/14fbbb8aed5c6a04685da2cee3f11b98d70304a7/src/clusterBed/clusterBed.cpp
IntegerVector result(starts.size());
int cluster_id = 0;
int prev_end = starts[0];
int cluster_id = -1;
int prev_end = std::numeric_limits<int>::min();
vector<int> indices = sort_indices<true>(as<std::vector<double> >(starts));
for (int j = 0; j < indices.size(); j++) {
int i = indices[j];
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test_cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ test_that("cluster_interval works", {
starts <- c(50, 100, 120, 180, 350)
ends <- c(75, 200, 150, 210, 400)
expect_equal(cluster_interval(starts, ends), c(0,1,1,1,2))

starts <- c(500, 300, 150)
ends <- c(510, 310, 160)
expect_equal(cluster_interval(start, end), c(2,1,0))

expect_equal(cluster_interval(numeric(0), numeric(0)), numeric(0))
})

0 comments on commit 8b8320a

Please sign in to comment.