Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. package msp
  2.  
  3. import (
  4. "testing"
  5. )
  6.  
  7. var testcases = [...]struct {
  8. n []int
  9. emaxSum int
  10. emi int
  11. emj int
  12. }{
  13. {[]int{1, -2, 2, 3, -4, -5}, 5, 2, 3},
  14. {[]int{1, 2, 3, 4}, 10, 0, 3},
  15. {[]int{-1, -2, -3}, -1, 0, 0},
  16. {[]int{-3, -2, -1}, -1, 2, 2},
  17. {[]int{0}, 0, 0, 0},
  18. {[]int{-1}, -1, 0, 0},
  19. {[]int{}, -1, -1, -1},
  20. {[]int{1, 2, 3, 4}, 10, 0, 3},
  21. {[]int{}, 10000, 9999, 9999},
  22. {[]int{0, 0, 1, 2, 3, 4, 0, 0}, 10, 0, 7},
  23. }
  24.  
  25. const largeN = 2000
  26.  
  27. func populateLargeData() {
  28. if len(testcases[8].n) == 0 {
  29. for i := 1; i < largeN; i++ {
  30. testcases[8].n = append(testcases[8].n, i*-1)
  31. }
  32. testcases[8].n = append(testcases[8].n, largeN)
  33. }
  34. testcases[8].emaxSum = largeN
  35. testcases[8].emi = largeN - 1
  36. testcases[8].emj = largeN - 1
  37. }
  38.  
  39. func TestMspN1(t *testing.T) {
  40. populateLargeData()
  41.  
  42. for _, tt := range testcases {
  43. maxSum, mi, mj := mspN1(tt.n)
  44. if maxSum != tt.emaxSum || mi != tt.emi || mj != tt.emj {
  45. t.Errorf("expected %v %v %v, got %v, %v, %v", tt.emaxSum, tt.emi, tt.emj, maxSum, mi, mj)
  46. }
  47. }
  48. }
  49.  
  50. func TestMspN2(t *testing.T) {
  51. populateLargeData()
  52.  
  53. for _, tt := range testcases {
  54. maxSum, mi, mj := mspN2(tt.n)
  55. if maxSum != tt.emaxSum || mi != tt.emi || mj != tt.emj {
  56. t.Errorf("expected %v %v %v, got %v, %v, %v", tt.emaxSum, tt.emi, tt.emj, maxSum, mi, mj)
  57. }
  58. }
  59. }
  60.  
  61. func TestMspN3(t *testing.T) {
  62. populateLargeData()
  63.  
  64. for _, tt := range testcases {
  65. maxSum, mi, mj := mspN3(tt.n)
  66. if maxSum != tt.emaxSum || mi != tt.emi || mj != tt.emj {
  67. t.Errorf("expected %v %v %v, got %v, %v, %v", tt.emaxSum, tt.emi, tt.emj, maxSum, mi, mj)
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement