Skip to content
Snippets Groups Projects

Main

Closed Maren.Solvag requested to merge Maren.Solvag/oblig3-myfs:main into main
2 files
+ 18
15
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 14
11
@@ -25,23 +25,26 @@ it, 'and what is the use of a book,' thought Alice 'without pictures or
conversations?'
"""
test_sample = "Did you know that the moon is made of cheese?"
test_sample = "Did you know that the moon is made of cheese?\0\0\0"
def test_1():
with open("test1.fs", 'r+b') as f:
with open("test1.fs", 'w+b') as f:
format(f) # clear the file system
try:
for i in range(7):
# Add 7 files (is max with the original capacity)
save(f, f"alice{i}.txt", f"content{i}")
# Remove 1 file, there should be more space now
remove(f, f"alice{i}.txt")
# try adding another file
save(f, f"hello.txt", f"Hello World!")
# Check that the new file is there
assert load(f, "hello.txt") == "Hello World!"
# Remove 1 file, there should be more space now
remove(f, "alice3.txt")
# try adding another file
save(f, "hello.txt", "Hello World!")
# Check that the new file is there
content = load(f, "hello.txt")
except Exception as e:
print(f"Test 1 failed: {e}")
content = ""
assert content == "Hello World!"
def test_2():
@@ -58,13 +61,15 @@ def test_3():
# test that block was not zeroed out when deleted
with open("test_remove_not_zeroed_out.fs", 'w+b') as f:
format(f)
f.seek(0)
clean_state = f.read()
save(f, "test.txt", test_sample)
remove(f, "test.txt")
# Check that the file system is not fully zeroed out
f.seek(0)
content = f.read()
assert any(byte != 0 for byte in content), "File system is fully zeroed out after removal"
assert content != clean_state, "File system is fully zeroed out after removal. It should not be"
def test_4():
@@ -76,13 +81,11 @@ def test_4():
# Test that the content is the same
content = load(f, "link.txt")
content = content.decode('utf-8')
assert content == test_sample
# Test that removing the original file does not affect the hard link
remove(f, "test.txt")
content = load(f, "link.txt")
content = content.decode('utf-8')
assert content == test_sample
# test that the file can be removed
Loading