arcfsm_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package calculator
  2. import (
  3. "flag"
  4. "go-common/app/service/main/upcredit/conf"
  5. "go-common/app/service/main/upcredit/model/upcrmmodel"
  6. "path/filepath"
  7. "testing"
  8. )
  9. func init() {
  10. dir, _ := filepath.Abs("../../cmd/upcredit-service.toml")
  11. flag.Set("conf", dir)
  12. conf.Init()
  13. }
  14. var (
  15. logs = []upcrmmodel.SimpleCreditLog{
  16. {Type: 1, OpType: -10, Reason: 0},
  17. {Type: 1, OpType: -1, Reason: 0},
  18. {Type: 1, OpType: -3, Reason: 0},
  19. {Type: 1, OpType: -1, Reason: 0},
  20. {Type: 1, OpType: -1, Reason: 0},
  21. {Type: 1, OpType: 0, Reason: 0},
  22. {Type: 1, OpType: 0, Reason: 0},
  23. {Type: 1, OpType: -9, Reason: 0},
  24. {Type: 1, OpType: 0, Reason: 0},
  25. {Type: 1, OpType: -30, Reason: 0},
  26. }
  27. )
  28. func TestArcFSM(t *testing.T) {
  29. var stat = creditStat{}
  30. var article = CreateArticleStateMachine(logs[0].OpType, logs[0].Type, logs[0].Reason)
  31. for i := 1; i < len(logs); i++ {
  32. article.OnLog(&logs[i], stat.onLogResult)
  33. }
  34. stat.CalcRelativeScore()
  35. stat.CalcTotalScore()
  36. t.Logf("stat: %+v", stat)
  37. }
  38. func TestArcFsmInitState(t *testing.T) {
  39. var fsm = CreateArticleStateMachineWithInitState()
  40. var init = conf.CreditConfig.ArticleRule.InitState
  41. if fsm.Round != init.Round ||
  42. fsm.Reason != init.Reason ||
  43. fsm.State != init.State {
  44. t.Errorf("fail to pass init state!")
  45. }
  46. }