Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oblig3-myFS
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ii
INF113
24H
Oblig3-myFS
Merge requests
!1
Main
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Main
Maren.Solvag/oblig3-myfs:main
into
main
Overview
0
Commits
2
Pipelines
0
Changes
2
Closed
Maren.Solvag
requested to merge
Maren.Solvag/oblig3-myfs:main
into
main
4 months ago
Overview
0
Commits
2
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Viewing commit
3b56b49f
Prev
Next
Show latest version
2 files
+
18
−
15
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
3b56b49f
Merge
· 3b56b49f
Maren Solvåg
authored
4 months ago
main.py
+
14
−
11
Options
@@ -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