コード例 #1
0
class TestAuction(unittest.TestCase):

    def setUp(self):
        self.testitem1 = Item("Car", 1000)
        self.testitem2 = Item("Boat", 10000)
        self.testitem3 = Item("Game", 100)
        self.testbidder1 = Bidder("John Doe")
        self.testbidder2 = Bidder("Jane Doe")

    # Test to check if when we add a bid, the bid stored in the item matches the added bid
    def test_add_bid_and_check_bid_methods(self):
        self.testitem1.addBid(1001, self.testbidder1)                    # Add bid by John to Car
        self.assertEqual(self.testitem1.getCurrentBid(), 1001)           # Check if the bid added matches amount stored

    # Test if adding a bidder with an argument creates that bidder object and we can access the bidder name
    def test_add_bidder(self):
        testbidder = Bidder("John Doe")                                   # Create bidder object
        self.assertEqual(testbidder.bidderName, "JOHN DOE")               # Check if there is a bidder with name

    # Check if the getItemsBidOn method retrieves the dictionary of items bid for
    def test_check_user_bid_hist_call(self):
        self.testitem1.addBid(1001, self.testbidder2)                     # Add bid by Jane to Car
        self.testitem2.addBid(10001, self.testbidder2)                    # Add bid by Jane to Boat
        bidhistdict = self.testbidder2.getItemsBidOn()                    # Make a dictionary using the method
        self.assertEqual(bidhistdict,self.testbidder2.itemsBidForDict)    # Check if it is the same as the items bid on

    # Check if we can get all the items for which a user has bid on
    def test_check_user_bid_hist(self):
        bidhistdict = self.testbidder1.getItemsBidOn()
        self.testitem2.addBid(10001, self.testbidder1)                     # Add a bid by John for Boat
        self.assertTrue("CAR" in bidhistdict and "BOAT" in self.testbidder1.getItemsBidOn())

    # Check if a bid is correctly stored in a the items bid history list
    def test_check_item_bid_hist(self):
        self.testitem1.addBid(1001.50, self.testbidder2)
        self.assertIn(('JANE DOE',1001.50),self.testitem1.bidList)

    # Check if item can be set as sold and we can check that status
    def test_check_item_set_as_sold(self):
        self.testitem1.changeStatus()                                       # Set as sold
        self.assertTrue(self.testitem1.soldStatus)                          # Check status

    # Test that if a string is added as a bid, the bid will not be registered
    def test_bid_error(self):
        self.testitem2.addBid("100000gbp",self.testbidder1)                 # Add bid with string as bid amount
        self.assertFalse(self.testitem2.bidstatus)                          # Check if bid has been made

    # Test that we can retrieve the winning bid of an item marked as sold
    def test_get_winning_bid(self):
        self.testitem2.addBid(99999, self.testbidder1)                      # Add a bid by John for Boat
        self.testitem2.changeStatus()                                       # Set it as sold
        self.assertEqual(self.testitem2.getwinningbid(),99999)              # Check if winning bid is equal to Johns bid

    # Test that we can retrieve the winning bidder of an item marked as sold
    def test_get_winning_bidder(self):
        self.testitem3.addBid(99999, self.testbidder1)
        self.testitem3.changeStatus()                                       # Set as sold
        self.assertEqual(self.testitem3.winner,"JOHN DOE")                  # Check if winner stored in item is right
コード例 #2
0
 def setUp(self):
     self.testitem1 = Item("Car", 1000)
     self.testitem2 = Item("Boat", 10000)
     self.testitem3 = Item("Game", 100)
     self.testbidder1 = Bidder("John Doe")
     self.testbidder2 = Bidder("Jane Doe")
コード例 #3
0
import socket
import threading
import sys
import Client_ui
from PyQt5.QtWidgets import QApplication, QMainWindow
from functools import partial
from Bidder import *

FINISH_FLAG = '1 Leave完成'  #断开客户端连接标识
BUFFER_SIZE = 1024  #一次UDP读取的字节数
PORT = 6666  #服务器端口
MY_BIDDER = Bidder()  #当前客户端的Bidder变量

app = QApplication(sys.argv)  #Ui界面是主线程,此线程退出则程序整体退出
MainWindow = QMainWindow()
ui = Client_ui.Ui_Server()
ui.setupUi(MainWindow)

client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  #套接字


def Print_received_msg(ui):
    while MY_BIDDER.is_logined():
        new_msg = client.recv(BUFFER_SIZE)
        new_msg = new_msg.decode('utf-8')
        if new_msg == FINISH_FLAG:  #输入leave命令则关闭当前套接字并退出
            MY_BIDDER.bidder_id = 0
            client.close()
            sys.exit(0)
        print(new_msg)
        if len(new_msg) > 1 and new_msg[0] in {'0', '1'} and new_msg[1] == ' ':