symbol_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package markinfo
  2. import "testing"
  3. func TestSymbolType(t *testing.T) {
  4. r, _ := SymbolType("EURUSD")
  5. if r != DIRECT_RATES {
  6. t.Errorf("SymbolType failed. Got %d, expected %d.", r, DIRECT_RATES)
  7. }
  8. r, _ = SymbolType("USDJPY")
  9. if r != INDIRECT_RATES {
  10. t.Errorf("SymbolType failed. Got %d, expected %d.", r, INDIRECT_RATES)
  11. }
  12. r, _ = SymbolType("EURJPY")
  13. if r != CROSS_RATES {
  14. t.Errorf("SymbolType failed. Got %d, expected %d.", r, CROSS_RATES)
  15. }
  16. _, err := SymbolType("EURJPY1")
  17. if err == nil {
  18. t.Errorf("SymbolType failed. unknow symbol ,but return no error.")
  19. }
  20. }
  21. func TestID(t *testing.T) {
  22. r, _ := SymbolId("EURUSD")
  23. if r != 2 {
  24. t.Errorf("SymbolUnit failed. Got %d, expected %d.", r, 2)
  25. }
  26. }
  27. func TestName(t *testing.T) {
  28. r, _ := SymbolName(2)
  29. if r != "EURUSD" {
  30. t.Errorf("SymbolUnit failed. Got %s, expected %s.", r, "EURUSD")
  31. }
  32. }
  33. func TestGetMap(t *testing.T) {
  34. r := SymbolMap()
  35. if r["EURUSD"] != 2 {
  36. t.Errorf("SymbolMap failed. ")
  37. }
  38. }
  39. func TestSymbolId2(t *testing.T) {
  40. id1, _ := SymbolId2("sh000001")
  41. id2, _ := SymbolId2("sz000001")
  42. if id1 == id2 {
  43. t.Errorf("deal sh000001 error.")
  44. }
  45. name1, _ := CustomSymbolName(id1)
  46. name2, _ := CustomSymbolName(id2)
  47. if name1 != "sh000001" {
  48. t.Errorf("SymbolName get sh000001 error.")
  49. }
  50. if name2 != "sz000001" {
  51. t.Errorf("SymbolName get sz000001 error.")
  52. }
  53. }