Skip to content
This repository was archived by the owner on Oct 12, 2020. It is now read-only.

Commit 8eeac49

Browse files
committed
Fixed one of the tests
1 parent 0f99eec commit 8eeac49

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

modules/geometry.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from PySide2.QtCore import QPoint, Qt
22
from PySide2 import QtGui
3+
import math
34

45

56
class Point(QPoint):
@@ -41,3 +42,15 @@ def plot(window, closedflag):
4142
window.pointNum,
4243
closedflag)
4344
window.image.setPixmap(QtGui.QPixmap().fromImage(graph))
45+
46+
def dist(a, b):
47+
x0 = int(a.x())
48+
y0 = int(a.y())
49+
x3 = int(b.x())
50+
y3 = int(b.y())
51+
x1 = x0 if x0 >= x3 else x3
52+
y1 = y0 if y0 >= y3 else y3
53+
x2 = x0 if x0 < x3 else x3
54+
y2 = y0 if y0 < y3 else y3
55+
dist = math.sqrt(((x1 - x2) ** 2) + ((y1 - y2) ** 2))
56+
return dist

tests/test_button.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytestqt
2-
from modules.gui import QtGui
3-
from modules.gui import Graph, QtWidgets
2+
from modules.gui import Graph, QtWidgets, QtGui
3+
from modules.geometry import dist, Point
44
from PySide2.QtCore import Qt
55
from os import path
66

@@ -16,11 +16,13 @@ def test_draw(qtbot):
1616
qtbot.waitForWindowShown(window)
1717

1818
qtbot.mouseClick(window.buttonBox.buttons()[0], Qt.LeftButton)
19-
20-
assert window.image.grab().toImage().pixelColor(window.p1) == Qt.black, ('Line not drawn'
21-
'or button '
22-
'not working')
23-
assert window.image.grab().toImage().pixelColor(window.p2) == Qt.black, ('Line not drawn'
19+
graph = window.image.grab().toImage()
20+
21+
for i in range(-20, 20):
22+
for j in range(-20, 20):
23+
p = Point(i, j)
24+
if dist(window.p1, p) + dist(window.p2, p) == dist(window.p1, window.p2):
25+
assert graph.pixelColor(p) == Qt.black, ('Line not drawn'
2426
'or button '
2527
'not working')
2628

0 commit comments

Comments
 (0)