Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unit Tests] - CalculateAverageDays #2228

Closed
tomsmith8 opened this issue Dec 19, 2024 · 3 comments · Fixed by #2236
Closed

[Unit Tests] - CalculateAverageDays #2228

tomsmith8 opened this issue Dec 19, 2024 · 3 comments · Fixed by #2236
Assignees

Comments

@tomsmith8
Copy link

Unit Test Coverage for "CalculateAverageDays"


Stakwork Run


Unit Test Code


File: /tmp/stakwork/sphinx-tribes/db/metrics.go


package metrics

import (
  "math"
  "testing"

  "github.com/stretchr/testify/assert"
)

// Assume SecondsToDateConversion is defined somewhere in the package
const SecondsToDateConversion = 86400 // Example value for seconds in a day

func TestCalculateAverageDays(t *testing.T) {
  tests := []struct {
  	name      string
  	paidCount int64
  	paidSum   uint
  	expected  uint
  }{
  	{
  		name:      "Standard Input",
  		paidCount: 10,
  		paidSum:   1000,
  		expected:  uint(math.Round(float64(1000/10) / float64(SecondsToDateConversion))),
  	},
  	{
  		name:      "Zero Paid Count",
  		paidCount: 0,
  		paidSum:   1000,
  		expected:  0,
  	},
  	{
  		name:      "Zero Paid Sum",
  		paidCount: 10,
  		paidSum:   0,
  		expected:  0,
  	},
  	{
  		name:      "Both Zero",
  		paidCount: 0,
  		paidSum:   0,
  		expected:  0,
  	},
  	{
  		name:      "Minimum Positive Values",
  		paidCount: 1,
  		paidSum:   1,
  		expected:  0,
  	},
  	{
  		name:      "Negative Paid Count",
  		paidCount: -1,
  		paidSum:   1000,
  		expected:  0,
  	},
  	{
  		name:      "Negative Paid Sum",
  		paidCount: 10,
  		paidSum:   0, // Negative values are not possible for uint, so set to 0
  		expected:  0,
  	},
  	{
  		name:      "Large Paid Count and Sum",
  		paidCount: 1000000,
  		paidSum:   1000000000,
  		expected:  uint(math.Round(float64(1000000000/1000000) / float64(SecondsToDateConversion))),
  	},
  	{
  		name:      "Paid Count Greater than Paid Sum",
  		paidCount: 1000,
  		paidSum:   500,
  		expected:  0,
  	},
  	{
  		name:      "Paid Sum Exactly Divisible by Paid Count",
  		paidCount: 5,
  		paidSum:   100,
  		expected:  uint(math.Round(float64(100/5) / float64(SecondsToDateConversion))),
  	},
  	{
  		name:      "Paid Sum Not Divisible by Paid Count",
  		paidCount: 3,
  		paidSum:   100,
  		expected:  uint(math.Round(float64(100/3) / float64(SecondsToDateConversion))),
  	},
  }

  for _, tt := range tests {
  	t.Run(tt.name, func(t *testing.T) {
  		result := CalculateAverageDays(tt.paidCount, tt.paidSum)
  		assert.Equal(t, tt.expected, result)
  	})
  }
}
@MahtabBukhari
Copy link
Contributor

MahtabBukhari commented Dec 19, 2024

@tomsmith8 is that available for work?
assign me

@aliraza556
Copy link
Contributor

aliraza556 commented Dec 19, 2024

@tomsmith8 Please assign me?

@MuhammadUmer44
Copy link
Contributor

@tomsmith8 assign me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants