Skip to content

Commit 700fded

Browse files
committed
initial commit
Signed-off-by: lifubang <[email protected]>
1 parent 1112196 commit 700fded

19 files changed

+410
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
acmdiffer

Diff for: Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
default: main.go
2+
go build -o acmdiffer

Diff for: README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## ACMDiffer
2+
```
3+
make
4+
./acmdiffer testdata/step.judger/user.out testdata/step.judger/data.out false false
5+
./acmdiffer testdata/step.judger/user.out testdata/step.judger/datav5.out false false
6+
```
7+
8+
## The Function
9+
```
10+
func DiffOut(userOut, dataOut string, diffIgnoreHead bool, strictMode bool) (bool, error)
11+
12+
```
13+
14+
## Params
15+
```
16+
userOut: user's output file
17+
dataOut: the test case file
18+
diffIgnoreHead: ignore the first line when comparing the contents
19+
strictMode: whether ignore the space and enter key or not when comparing the contents
20+
```

Diff for: go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/acmcode/differ
2+
3+
go 1.17

Diff for: main.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/acmcode/differ/tool"
8+
)
9+
10+
// The entrance of the app
11+
func main() {
12+
if len(os.Args) == 5 {
13+
userOut := os.Args[1]
14+
dataOut := os.Args[2]
15+
diffIgnoreHead := os.Args[3]
16+
strictMode := os.Args[4]
17+
isSame, err := tool.DiffOut(userOut, dataOut, diffIgnoreHead == "true", strictMode == "true")
18+
if err != nil {
19+
fmt.Println(err)
20+
} else {
21+
if isSame {
22+
fmt.Printf("'%s' is the same as '%s'\n", userOut, dataOut)
23+
} else {
24+
fmt.Printf("'%s' is not the same as '%s'\n", userOut, dataOut)
25+
}
26+
}
27+
} else {
28+
fmt.Println("Usage: ./acmdiffer user.out data.out false false")
29+
}
30+
}

Diff for: testdata/step.judger/data.out

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
aa bb
2+
cc dd
3+
ee ff
4+
HH II
5+
ss tt
6+
uu vv tt

Diff for: testdata/step.judger/datav1.out

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.2*2.1*11*2112*111112*12*3**2*3*211.12*1111...1*
2+
.2*2.22213*33*421*11*223*33333*33*2.1*322*322233
3+
.111.1*114*5***11111111*211*12*33*2.12*23*3**2**
4+
.....1112***3321......111.22323*3221112*21222233
5+
......113*421..........1222*2*33*11*1.1222221.1*
6+
..111.1*3321...111....12**32212*21111.13*4**1.22
7+
.12*1.23*2*1...1*1....1*33*21.222.....2***43323*
8+
.1*21.2*3211..1221....22212*1.1*1.....2*533*2**2
9+
.111..2*2..1111*21....1*1.1121322..111112*212221
10+
11.122211..1*112*1..12321...1*2*1..1*1..111.....
11+
*212**1....2231211..1**1....11211..111..........
12+
2*12*4311112*2*21.112221111......111..111.......
13+
11112*2*22*2122*1.1*1...1*211....2*2..1*1.......
14+
11..11213*32112231211...112*1....2*2..122211....
15+
*2....124*21*11*2*1....11112321..1122223*3*1..11
16+
*2....1**3221111211.1111*1.1**31.112**3**421.13*
17+
11...12322*1........1*1111136**1.1*2223*4*2111**
18+
.11212*1.111.....1122333211***41.111..12322*236*
19+
12*2*32211.......1*2*2***2234*31.......1*1112***
20+
2*443*22*1..111.1222123433*223*1.....11211.12332
21+
*3**322*22111*1.1*1...1*13*32*31..1223*2...1*1..
22+
2434*11111*1111.111.112123*22*2...1**4*4221211..
23+
*2*211..1221...112111*112*211221..123*3**2*1....
24+
1211....1*1....1*3*12221*21..1*1....11222211....
25+
..111...222....23*211*2221...23421.111..........
26+
112*1...1*21...2*31.113*2..112***1.1*1...1221...
27+
2*32312122*21..3*3....2*2..1*33421.1111111**2211
28+
*32*2*2*112*1..3*3111.111..112*1......1*2223*2*2
29+
*32121211.1221.2*22*2........111..122112*1.1122*
30+
2*1........1*1.1112*2.............1**22221....22
31+
222111..11122311.122111211111.111.234*2*1.12211*
32+
1*12*2112*11*2*112*112*3*21*223*211*21322.2**111
33+
1112*32*223322222*211*23*2113**4*2211.1*1.2*3222
34+
..123*2111**1.2*3111221111..3*5*4*3111211.1111**
35+
..1*212111221.2*2.13*311....2*314**21*21111..122
36+
11211.1*22111122211**4*2...1221.2**312*11*211...
37+
1*221112*2*22*11*11345*2...1*21113*2.223334*2...
38+
12*3*2.11223*32211.1**431.1333*1.111.1*3**3*2...
39+
.113*2....1*22*1111234**112**322.111.12*43311...
40+
.11211...13321111*11*22322*333*1.2*2..234*222111
41+
.1*1...112**2121211111.1*2111*21.2*2..1**44**11*
42+
.111...1*2222*2*1..1221222..111..1111123**3*3233
43+
.111...1221.12321..1**11*21211......2*32233211**
44+
.1*111212*1..1*21.12321123*2*1.112223**1.2*31122
45+
.1111*3*422..13*212*1...1*2211.1*2**3221.2**1...
46+
.111113*3*211.2*21*2111111211.12235*52111333211.
47+
13*21122322*1.112332.1*2111*212*21****21*2*11*1.
48+
*3*21*12*2222...1**1.112*113*22*324*5*211211111.
49+
12122223*21*1...1221...222.2*3222*22321111...111
50+
1223*21*43211.111.....13*2.112*22111*1.1*21112*1
51+
1**4*223**21..2*2111..1**3...23*1.1222122*11*211
52+
24*4221*44*21.2*43*1..24*2...1*21.1*11*1111111..
53+
*212*112*23*2.12**22222*321..11111211111..111.11
54+
122321.1113*3..12211**323*11221.2*2111..123*1.1*
55+
.1**1...113*31.....1222*2111**313*21*2222**32222
56+
.24542212*23*2111.....1111123*3*211112**3322*2*1
57+
.1****4*2223*21*1........2*32121211..123*2112321
58+
12345**322*211122211....13**1.112*2111223*1.2*2.
59+
1*11*322*2111122*2*1...12*321.1*22*11*3*211.3*3.
60+
112221.222..1*2*331211.1*21..122222112*21...2*31
61+
..2*31.1*2111123*2.1*1.111...2*32*1.1221...123*2
62+
..2**1.112*1...2*312221......2*3*32.1*1..112*22*
63+
.1232211.111..1334*32*11221..1122*22321..1*21111
64+
12*1.1*1...1111**4*3*211**2221..112**1...222111.
65+
1*22121211.1*1234*3311.1222**1....2331...1*11*21
66+
2211*211*1.1111*22*1..111.1222221.2*2....222124*
67+
*1.12*11221...222112222*1.1112**213*422222*1.1**
68+
1111211.1*11111*1..1**211.1*35*42*22**2**211.233
69+
111*1...1122*1112122432.1122***42112332332...1*1
70+
*111211..12*22223*4*2*1.1*1124**1..1*1.1*1.11211
71+
331.1*21.1*321**3**22111221..1221..222.11212*1..
72+
**2123*2.12*11222221...1*1.111.11212*1...1*2221.
73+
233*23*2.1221......112232113*2.2*3*211...1122*1.
74+
.1*22*21.1*21111...1*2**1.1**2.2*311....1112*31.
75+
1221111..12*22*332111333112321.111..111.2*22*211
76+
1*21..1221224*4***2..1*113*2.111....1*1.2*21111*
77+
12*1..1**11*3*335*2..1112**2.1*211.1221.111...11
78+
.111..1221112111*21.....2*31.112*1.1*1..........

Diff for: testdata/step.judger/datav2.out

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 2 3
2+
4
3+
5 6

Diff for: testdata/step.judger/datav3.out

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3

Diff for: testdata/step.judger/datav4.out

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name
2+
李福帮
3+
李福帮1

Diff for: testdata/step.judger/datav5.out

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
4
3+
4
4+
5+
3

Diff for: testdata/step.judger/user.out

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
aa bb
2+
cc dd
3+
ee ff
4+
HH II
5+
ss tt
6+
uu vv tt

Diff for: testdata/step.judger/userv1.out

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.2*2.1*11*2112*111112*12*3**2*3*211.12*1111...1*
2+
.2*2.22213*33*421*11*223*33333*33*2.1*322*322233
3+
.111.1*114*5***11111111*211*12*33*2.12*23*3**2**
4+
.....1112***3321......111.22323*3221112*21222233
5+
......113*421..........1222*2*33*11*1.1222221.1*
6+
..111.1*3321...111....12**32212*21111.13*4**1.22
7+
.12*1.23*2*1...1*1....1*33*21.222.....2***43323*
8+
.1*21.2*3211..1221....22212*1.1*1.....2*533*2**2
9+
.111..2*2..1111*21....1*1.1121322..111112*212221
10+
11.122211..1*112*1..12321...1*2*1..1*1..111.....
11+
*212**1....2231211..1**1....11211..111..........
12+
2*12*4311112*2*21.112221111......111..111.......
13+
11112*2*22*2122*1.1*1...1*211....2*2..1*1.......
14+
11..11213*32112231211...112*1....2*2..122211....
15+
*2....124*21*11*2*1....11112321..1122223*3*1..11
16+
*2....1**3221111211.1111*1.1**31.112**3**421.13*
17+
11...12322*1........1*1111136**1.1*2223*4*2111**
18+
.11212*1.111.....1122333211***41.111..12322*236*
19+
12*2*32211.......1*2*2***2234*31.......1*1112***
20+
2*443*22*1..111.1222123433*223*1.....11211.12332
21+
*3**322*22111*1.1*1...1*13*32*31..1223*2...1*1..
22+
2434*11111*1111.111.112123*22*2...1**4*4221211..
23+
*2*211..1221...112111*112*211221..123*3**2*1....
24+
1211....1*1....1*3*12221*21..1*1....11222211....
25+
..111...222....23*211*2221...23421.111..........
26+
112*1...1*21...2*31.113*2..112***1.1*1...1221...
27+
2*32312122*21..3*3....2*2..1*33421.1111111**2211
28+
*32*2*2*112*1..3*3111.111..112*1......1*2223*2*2
29+
*32121211.1221.2*22*2........111..122112*1.1122*
30+
2*1........1*1.1112*2.............1**22221....22
31+
222111..11122311.122111211111.111.234*2*1.12211*
32+
1*12*2112*11*2*112*112*3*21*223*211*21322.2**111
33+
1112*32*223322222*211*23*2113**4*2211.1*1.2*3222
34+
..123*2111**1.2*3111221111..3*5*4*3111211.1111**
35+
..1*212111221.2*2.13*311....2*314**21*21111..122
36+
11211.1*22111122211**4*2...1221.2**312*11*211...
37+
1*221112*2*22*11*11345*2...1*21113*2.223334*2...
38+
12*3*2.11223*32211.1**431.1333*1.111.1*3**3*2...
39+
.113*2....1*22*1111234**112**322.111.12*43311...
40+
.11211...13321111*11*22322*333*1.2*2..234*222111
41+
.1*1...112**2121211111.1*2111*21.2*2..1**44**11*
42+
.111...1*2222*2*1..1221222..111..1111123**3*3233
43+
.111...1221.12321..1**11*21211......2*32233211**
44+
.1*111212*1..1*21.12321123*2*1.112223**1.2*31122
45+
.1111*3*422..13*212*1...1*2211.1*2**3221.2**1...
46+
.111113*3*211.2*21*2111111211.12235*52111333211.
47+
13*21122322*1.112332.1*2111*212*21****21*2*11*1.
48+
*3*21*12*2222...1**1.112*113*22*324*5*211211111.
49+
12122223*21*1...1221...222.2*3222*22321111...111
50+
1223*21*43211.111.....13*2.112*22111*1.1*21112*1
51+
1**4*223**21..2*2111..1**3...23*1.1222122*11*211
52+
24*4221*44*21.2*43*1..24*2...1*21.1*11*1111111..
53+
*212*112*23*2.12**22222*321..11111211111..111.11
54+
122321.1113*3..12211**323*11221.2*2111..123*1.1*
55+
.1**1...113*31.....1222*2111**313*21*2222**32222
56+
.24542212*23*2111.....1111123*3*211112**3322*2*1
57+
.1****4*2223*21*1........2*32121211..123*2112321
58+
12345**322*211122211....13**1.112*2111223*1.2*2.
59+
1*11*322*2111122*2*1...12*321.1*22*11*3*211.3*3.
60+
112221.222..1*2*331211.1*21..122222112*21...2*31
61+
..2*31.1*2111123*2.1*1.111...2*32*1.1221...123*2
62+
..2**1.112*1...2*312221......2*3*32.1*1..112*22*
63+
.1232211.111..1334*32*11221..1122*22321..1*21111
64+
12*1.1*1...1111**4*3*211**2221..112**1...222111.
65+
1*22121211.1*1234*3311.1222**1....2331...1*11*21
66+
2211*211*1.1111*22*1..111.1222221.2*2....222124*
67+
*1.12*11221...222112222*1.1112**213*422222*1.1**
68+
1111211.1*11111*1..1**211.1*35*42*22**2**211.233
69+
111*1...1122*1112122432.1122***42112332332...1*1
70+
*111211..12*22223*4*2*1.1*1124**1..1*1.1*1.11211
71+
331.1*21.1*321**3**22111221..1221..222.11212*1..
72+
**2123*2.12*11222221...1*1.111.11212*1...1*2221.
73+
233*23*2.1221......112232113*2.2*3*211...1122*1.
74+
.1*22*21.1*21111...1*2**1.1**2.2*311....1112*31.
75+
1221111..12*22*332111333112321.111..111.2*22*211
76+
1*21..1221224*4***2..1*113*2.111....1*1.2*21111*
77+
12*1..1**11*3*335*2..1112**2.1*211.1221.111...11
78+
.111..1221112111*21.....2*31.112*1.1*1..........

Diff for: testdata/step.judger/userv2.out

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1
2+
2
3+
3
4+
4
5+
5
6+
6

Diff for: testdata/step.judger/userv3.out

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3

Diff for: testdata/step.judger/userv4.out

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
myname1
2+
李福帮
3+
李福帮1

Diff for: testdata/step.judger/userv5.out

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
3
2+
3+
4
4+
5+
4
6+
7+
3
8+

Diff for: tool/differ.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package tool
2+
3+
import (
4+
"bufio"
5+
"os"
6+
"strings"
7+
)
8+
9+
// DiffOut is to diff the output between user and testcase
10+
// TODO: we need to implement the "strictMode" mode in the future.
11+
func DiffOut(userOut, dataOut string, diffIgnoreHead bool, strictMode bool) (bool, error) {
12+
src, err := os.Open(userOut)
13+
if err != nil {
14+
return false, err
15+
}
16+
defer src.Close()
17+
dst, err := os.Open(dataOut)
18+
if err != nil {
19+
return false, err
20+
}
21+
defer dst.Close()
22+
23+
var strSrc, strDest strings.Builder
24+
25+
rd := bufio.NewScanner(src)
26+
srcIgnoreHead := diffIgnoreHead
27+
for rd.Scan() {
28+
str := rd.Text()
29+
trimStr := strings.Trim(str, " ")
30+
if srcIgnoreHead {
31+
srcIgnoreHead = false
32+
} else {
33+
if len(trimStr) > 0 {
34+
strSrc.WriteString(trimStr + " ")
35+
}
36+
}
37+
}
38+
39+
rd = bufio.NewScanner(dst)
40+
dstIgnoreHead := diffIgnoreHead
41+
for rd.Scan() {
42+
str := rd.Text()
43+
trimStr := strings.Trim(str, " ")
44+
if dstIgnoreHead {
45+
dstIgnoreHead = false
46+
} else {
47+
if len(trimStr) > 0 {
48+
strDest.WriteString(trimStr + " ")
49+
}
50+
}
51+
}
52+
53+
return strings.Trim(strSrc.String(), " ") == strings.Trim(strDest.String(), " "), nil
54+
}

0 commit comments

Comments
 (0)