Skip to content

Commit 536c0ef

Browse files
committed
fix checksum validation for parseStandardDataset
1 parent a51105f commit 536c0ef

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ go get github.com/dmachard/go-ticreader
1616

1717
## Utilisation
1818

19+
### Choix du mode de fonctionnement
20+
21+
- `ticreader.ModeHistorical`
22+
- `ticreader.ModeStandard`
23+
1924
### Example basique
2025

2126
```go

parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ func parseStandardDataset(dataset string) (Dataset, error) {
118118
data := parts[2]
119119
checksum := parts[3]
120120

121-
valid := verifyChecksum(checksum, label+"\t"+horodate+"\t"+data)
121+
valid := verifyChecksum(checksum, label+"\t"+horodate+"\t"+data+"\t")
122122
return Dataset{Label: label, Horodate: horodate, Data: data, Valid: valid, Checksum: checksum}, nil
123123

124124
} else if len(parts) == 3 { // Sans horodatage
125125
label := parts[0]
126126
data := parts[1]
127127
checksum := parts[2]
128128

129-
valid := verifyChecksum(checksum, label+"\t"+data)
129+
valid := verifyChecksum(checksum, label+"\t"+data+"\t")
130130
return Dataset{Label: label, Data: data, Valid: valid, Checksum: checksum}, nil
131131
}
132132

parser_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestParseHistoricDataset(t *testing.T) {
5454
}
5555

5656
func TestParseStandardDataset(t *testing.T) {
57-
frame := "ADCO\t021528603314\t#"
57+
frame := "ADCO\t1234567890123\t,"
5858
dataset, err := parseStandardDataset(frame)
5959
if err != nil {
6060
t.Errorf("Unexpected error: %s", err)
@@ -64,8 +64,8 @@ func TestParseStandardDataset(t *testing.T) {
6464
t.Errorf("Expected label ADCO, got %s", dataset.Label)
6565
}
6666

67-
if dataset.Data != "021528603314" {
68-
t.Errorf("Expected data 021528603314, got %s", dataset.Data)
67+
if dataset.Data != "1234567890123" {
68+
t.Errorf("Expected data 1234567890123, got %s", dataset.Data)
6969
}
7070

7171
if dataset.Valid != true {
@@ -80,8 +80,10 @@ func TestCalculateChecksum(t *testing.T) {
8080
}{
8181
{"IINST 002", "Y"}, // historical format
8282
{"IMAX 090", "H"},
83-
{"IINST\t002", "B"}, // standard format sans horodatage
84-
{"ADCO\t021528603314", "#"},
83+
{"SINSTS\t00520\t", "M"}, // standard format sans horodatage
84+
{"SMAXSN\tH250221001022\t02560\t", "+"}, // avec horodatages
85+
{"STGE\t003AC001\t", "M"},
86+
{"ADCO\t1234567890123\t", ","},
8587
}
8688

8789
for _, test := range tests {

0 commit comments

Comments
 (0)