sio-2425/delivery1/lib/tests/test_digest.py

36 lines
1.0 KiB
Python

import os
from digest import *
def test_equal_string():
string_one = "Hello, World!"
string_two = "Hello, World!"
assert get_hash(bytes(string_one, 'utf-8')) == get_hash(bytes(string_two, 'utf-8'))
def test_diff_string():
string_one = "Hello, World!"
string_two = "Hello, World"
assert get_hash(bytes(string_one, 'utf-8')) != get_hash(bytes(string_two, 'utf-8'))
def test_equal_file():
# create equal files
os.system("dd if=/dev/zero of=test.txt bs=1024 count=1000 >/dev/null 2>&1")
os.system("dd if=/dev/zero of=test2.txt bs=1024 count=1000 >/dev/null 2>&1")
assert get_hash(open("test.txt", "rb").read()) == get_hash(open("test2.txt", "rb").read())
os.remove("test.txt")
os.remove("test2.txt")
def test_diff_file():
# create different files
os.system("dd if=/dev/urandom of=test.txt bs=1024 count=1000 >/dev/null 2>&1")
os.system("dd if=/dev/urandom of=test2.txt bs=1024 count=1000 >/dev/null 2>&1")
assert get_hash(open("test.txt", "rb").read()) != get_hash(open("test2.txt", "rb").read())
os.remove("test.txt")
os.remove("test2.txt")