Skip to content

Commit

Permalink
Rename consensus.subset_clust to consensus.downsample_by_label to…
Browse files Browse the repository at this point in the history
… clarify the function's purpose.
  • Loading branch information
akikuno committed May 24, 2024
1 parent 70f675d commit f6e3f0b
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
from DAJIN2.core.consensus.clust_formatter import subset_clust
from DAJIN2.core.consensus.clust_formatter import downsample_by_label


def test_basic_subset_clust():
def test_basic_downsample_by_label():
sample = [{"LABEL": 1, "DATA": i} for i in range(1500)]
subset = subset_clust(sample)
subset = downsample_by_label(sample)
assert len(subset) == 1000 # Default num value is 1000
assert all(item["LABEL"] == 1 for item in subset)


def test_subset_clust_with_custom_num():
def test_downsample_by_label_with_custom_num():
sample = [{"LABEL": 1, "DATA": i} for i in range(1500)]
subset = subset_clust(sample, num=500)
subset = downsample_by_label(sample, num=500)
assert len(subset) == 500


def test_subset_clust_with_multiple_labels():
def test_downsample_by_label_with_multiple_labels():
sample = [{"LABEL": 1, "DATA": i} for i in range(500)] + [{"LABEL": 2, "DATA": i} for i in range(500)]
subset = subset_clust(sample)
subset = downsample_by_label(sample)
assert len(subset) == 1000
assert len([item for item in subset if item["LABEL"] == 1]) == 500
assert len([item for item in subset if item["LABEL"] == 2]) == 500


def test_subset_clust_with_less_than_num():
def test_downsample_by_label_with_less_than_num():
sample = [{"LABEL": 1, "DATA": i} for i in range(400)]
subset = subset_clust(sample, num=500)
subset = downsample_by_label(sample, num=500)
assert len(subset) == 400


def test_subset_clust_with_multiple_labels_with_less_than_nu():
def test_downsample_by_label_with_multiple_labels_with_less_than_nu():
sample = [{"LABEL": 1, "DATA": i} for i in range(500)] + [{"LABEL": 2, "DATA": i} for i in range(500)]
subset = subset_clust(sample, num=200)
subset = downsample_by_label(sample, num=200)
assert len(subset) == 400
assert len([item for item in subset if item["LABEL"] == 1]) == 200
assert len([item for item in subset if item["LABEL"] == 2]) == 200


def test_subset_clust_with_empty_sample():
def test_downsample_by_label_with_empty_sample():
sample = []
subset = subset_clust(sample)
subset = downsample_by_label(sample)
assert len(subset) == 0

0 comments on commit f6e3f0b

Please sign in to comment.