Skip to content

Commit fd24fcf

Browse files
committed
test: modify reference
1 parent a7bcc5f commit fd24fcf

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
etotref -211.6639823992573
22
etotperatomref -105.8319911996
3-
CompareH_Failed 0
4-
CompareS_Failed 0
3+
CompareH_pass 0
4+
CompareS_pass 0
55
totaltimeref 1.0405
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
etotref -204.4576701851543
22
etotperatomref -102.2288350926
3-
CompareHR_Failed 0
4-
CompareSR_Failed 0
3+
CompareHR_pass 0
4+
CompareSR_pass 0
55
totaltimeref 1.0391
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
etotref -204.5417148291529
22
etotperatomref -102.2708574146
3-
CompareH_Failed 0
4-
CompareS_Failed 0
3+
CompareH_pass 0
4+
CompareS_pass 0
55
totaltimeref 2.8028

tests/integrate/tools/CompareFile.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import os,sys
33

44
usage = '''
5-
python CompareFile.py file1 file2 [accuracy]
5+
python CompareFile.py file1 file2 [accuracy] [-abs 0]
66
77
accuracy - the accuracy of two float value.
88
default value is 8, which means
99
pass when the difference of two
1010
value is smaller than 1e-8.
11+
-abs - if compare the absolute value, default is False
1112
1213
This script is used to compare whether two files are
1314
same.
@@ -20,15 +21,23 @@
2021
'''
2122

2223
def ReadParam():
23-
if len(sys.argv) not in [3,4]:
24+
if len(sys.argv) not in [3,4,5,6]:
2425
print(usage)
2526
sys.exit(1)
2627
file1 = sys.argv[1]
2728
file2 = sys.argv[2]
2829
accur = 8
29-
if len(sys.argv) == 4: accur = int(sys.argv[3])
30+
absolute = False
31+
if len(sys.argv) == 4:
32+
accur = int(sys.argv[3])
33+
elif len(sys.argv) == 5 and sys.argv[3] == '-abs':
34+
absolute = bool(sys.argv[4])
35+
elif len(sys.argv) == 6:
36+
accur = int(sys.argv[3])
37+
absolute = bool(sys.argv[5])
38+
3039
epsilon = 0.1**accur
31-
return file1,file2,epsilon
40+
return file1,file2,epsilon,absolute
3241

3342
def ReadFile(file1,lines):
3443
if os.path.isfile(file1):
@@ -69,7 +78,7 @@ def ExitError(iline,line1,line2,jnumber=-1):
6978

7079

7180
if __name__ == "__main__":
72-
file1,file2,epsilon = ReadParam()
81+
file1,file2,epsilon,absolute = ReadParam()
7382
lines1 = []
7483
lines2 = []
7584
ReadFile(file1,lines1)
@@ -86,8 +95,19 @@ def ExitError(iline,line1,line2,jnumber=-1):
8695
x1 = IsComplex(sline1[j])
8796
x2 = IsComplex(sline2[j])
8897
if x1 and x2:
89-
if abs(x1[0] - x2[0]) > epsilon: ExitError(i,sline1[j],sline2[j],j)
90-
if abs(x1[1] - x2[1]) > epsilon: ExitError(i,sline1[j],sline2[j],j)
98+
if absolute:
99+
if abs((x1[0]**2+x1[1]**2)**0.5 - (x2[0]**2+x2[1]**2)**0.5) > epsilon:
100+
ExitError(i,sline1[j],sline2[j],j)
101+
else:
102+
if abs(x1[0] - x2[0]) > epsilon:
103+
ExitError(i,sline1[j],sline2[j],j)
104+
if abs(x1[1] - x2[1]) > epsilon:
105+
ExitError(i,sline1[j],sline2[j],j)
91106
elif IsFloat(sline1[j]) and IsFloat(sline2[j]):
92-
if abs(float(sline1[j]) - float(sline2[j])) > epsilon: ExitError(i,sline1[j],sline2[j],j)
107+
if absolute:
108+
if abs(abs(float(sline1[j])) - abs(float(sline2[j]))) > epsilon:
109+
ExitError(i,sline1[j],sline2[j],j)
110+
else:
111+
if abs(float(sline1[j]) - float(sline2[j])) > epsilon:
112+
ExitError(i,sline1[j],sline2[j],j)
93113
elif sline1[j] != sline2[j]: ExitError(i,sline1[j],sline2[j],j)

tests/integrate/tools/catch_properties.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ if ! test -z "$has_lowf" && [ $has_lowf -eq 1 ]; then
201201
wfc_ref=LOWF_K_2_mod.dat.ref
202202
fi
203203

204-
python3 ../tools/CompareFile.py $wfc_cal $wfc_ref 8
204+
python3 ../tools/CompareFile.py $wfc_cal $wfc_ref 8 -abs 1
205205
echo "Compare_wfc_lcao_pass $?" >>$1
206206
fi
207207

0 commit comments

Comments
 (0)