diff --git a/data_scheduler.go b/data_scheduler.go index e77c891..eb63230 100644 --- a/data_scheduler.go +++ b/data_scheduler.go @@ -29,6 +29,10 @@ func CalculateBucketSize(data_length int, minimum_bins int, bucket_increase int) } bucket_size := (data_length / minimum_bins) + if bucket_size == 0 { + bucket_size++ + } + remainder := data_length % minimum_bins if remainder == 0 { @@ -48,6 +52,7 @@ func CalculateBucketSize(data_length int, minimum_bins int, bucket_increase int) bucket_size *= bucket_increase minimum_bins = data_length / bucket_size } + return bucket_size, minimum_bins } diff --git a/data_scheduler_test.go b/data_scheduler_test.go index 614f14c..d06221f 100644 --- a/data_scheduler_test.go +++ b/data_scheduler_test.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "fmt" "os" "path" "testing" @@ -50,12 +49,37 @@ func TestRunData(t *testing.T) { // Compare outputs line by line f1, _ := os.ReadFile(test_expected_output) f2, _ := os.ReadFile(test_output_file) - fmt.Println(string(f2)) if !bytes.Equal(f1, f2) { t.Fatal("Input and output files to not match.") } } +func TestRunDataSmall(t *testing.T) { + tempdir := t.TempDir() + + t.Log("Starting end to end test for distance calculations.") + test_input := "TestInputs/DistanceMatrix/Random_2_input.txt" + test_output_file := path.Join(tempdir, "output.txt") + + t.Logf("Test Input: %s", test_input) + t.Logf("Test Output Temp File: %s", test_output_file) + t.Log("Creating output buffer.") + out_buffer, out_file := CreateOutputBuffer(test_output_file) + + t.Log("Loading test allele profiles.") + test_data := LoadProfile(test_input) + RunData(test_data, out_buffer) + out_buffer.Flush() + out_file.Close() + + // Compare outputs line by line + f2, _ := os.ReadFile(test_output_file) + output := string(f2) + if output != "1 1 0\n" { + t.Fatal("Input does not equal output.") + } +} + // Testing the redistribution of bucket indices at runtime func TestRedistributeBuckets(t *testing.T) { var profile_size int = 100