service_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package service
  2. import (
  3. "testing"
  4. )
  5. type c struct {
  6. balance int64
  7. loss int64
  8. expectUserRefund int64
  9. expectBizRefund int64
  10. }
  11. func TestCalcRefundFee(t *testing.T) {
  12. var min int64 = -20000
  13. cases := []c{
  14. c{
  15. balance: 10000,
  16. loss: 20000,
  17. expectUserRefund: 20000,
  18. expectBizRefund: 0,
  19. }, c{
  20. balance: 0,
  21. loss: 10000,
  22. expectUserRefund: 10000,
  23. expectBizRefund: 0,
  24. }, c{
  25. balance: -1,
  26. loss: 20000,
  27. expectUserRefund: 19999,
  28. expectBizRefund: 1,
  29. }, c{
  30. balance: -19999,
  31. loss: 20000,
  32. expectUserRefund: 1,
  33. expectBizRefund: 19999,
  34. }, c{
  35. balance: -20000,
  36. loss: 20000,
  37. expectUserRefund: 0,
  38. expectBizRefund: 20000,
  39. }, c{
  40. balance: -30000,
  41. loss: 20000,
  42. expectUserRefund: 0,
  43. expectBizRefund: 20000,
  44. },
  45. }
  46. for _, c := range cases {
  47. bizRefund, userRefund := calcRefundFee(c.balance, c.loss, min)
  48. if userRefund != c.expectUserRefund {
  49. t.Fatalf("TestCalcRefundFee case: %+v expectUserRefund not right, actual: %d\n", c, userRefund)
  50. }
  51. if bizRefund != c.expectBizRefund {
  52. t.Fatalf("TestCalcRefundFee case: %+v expectBizRefund not right, actual: %d\n", c, bizRefund)
  53. }
  54. }
  55. }