Compare commits

..

3 Commits

Author SHA1 Message Date
Isaac Shoebottom
d5c907859b Add lab 14 content and journal skeleton 2022-10-31 09:58:30 -03:00
Isaac Shoebottom
f45f47b572 Add lab 13 skeleton 2022-10-31 09:58:03 -03:00
Isaac Shoebottom
4daea2121b Update gitignore to include python files 2022-10-31 09:57:29 -03:00
24 changed files with 263 additions and 1 deletions

4
.gitignore vendored
View File

@ -1,2 +1,4 @@
*.bak
.nyc_output
.nyc_output
.pytest_cache
.coverage

View File

@ -0,0 +1,9 @@
Title: Lab Thirteen
Date: 2022-10-26T08:30:00
Tags: cs2613, lab, javascript
Sample description
<!-- more -->
## Sample Body
Sample Body

View File

@ -0,0 +1,9 @@
Title: Lab Fourteen
Date: 2022-10-31T08:30:00
Tags: cs2613, lab, python
Sample description
<!-- more -->
## Sample Body
Sample Body

39
labs/L13/animation.js Normal file
View File

@ -0,0 +1,39 @@
// let str="";
// for (let i=0; i<60; i++) {
// console.log('\033c');
// str+= "*";
// console.log(str);
// }
//console.log("all done!");
// function loop(i,str) {
// if (i>0) {
// console.log("\033c");
// console.log(str);
// setTimeout(function() { loop(i-1, str+"*"); }, 1000);
// }
// }
// loop(20,"*");
// console.log("all done!");
function animate(iterations) {
let i=0;
let str="*";
let timer = null;
function frame() {
console.log('\033c');
console.log(str);
if (i>=iterations) {
clearInterval(timer);
console.log("all done!");
}
}
timer=setInterval(frame,300);
}
animate(20);

8
labs/L14/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

10
labs/L14/.idea/L14.iml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name=".coverage" uuid="af2f1fdd-3241-4470-93b5-53f58bcdd0d2">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:C:\Users\Isaac\OneDrive - University of New Brunswick\Year 3 UNB\CS2613\Git\cs2613-ishoebot\labs\L14\.coverage</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
labs/L14/.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (L14)" project-jdk-type="Python SDK" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/L14.iml" filepath="$PROJECT_DIR$/.idea/L14.iml" />
</modules>
</component>
</project>

6
labs/L14/.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

16
labs/L14/client.py Normal file
View File

@ -0,0 +1,16 @@
import humansize
def approximate_size(size):
"""Returns the size of a file in a human-readable format where kilobytes are 1000 bytes
:param size: the size of a file
:return: string
"""
return humansize.approximate_size(size, False)
if __name__ == '__main__': # pragma: no cover
print(approximate_size(1_000))
print(approximate_size(100_000_000))
print(approximate_size(1_000_000_000))

8
labs/L14/divisive.py Normal file
View File

@ -0,0 +1,8 @@
import math
def fraction(a, b):
try:
return a / b
except ZeroDivisionError:
return math.nan

10
labs/L14/fizzbuzz.py Normal file
View File

@ -0,0 +1,10 @@
if __name__ == '__main__':
for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)

67
labs/L14/humansize.py Normal file
View File

@ -0,0 +1,67 @@
"""Convert file sizes to human-readable form.
Available functions:
approximate_size(size, a_kilobyte_is_1024_bytes)
takes a file size and returns a human-readable string
Examples:
>>> approximate_size(1024)
'1.0 KiB'
>>> approximate_size(1000, False)
'1.0 KB'
"""
SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}
def approximate_size(size, a_kilobyte_is_1024_bytes=True):
"""Convert a file size to human-readable form.
Keyword arguments:
size -- file size in bytes
a_kilobyte_is_1024_bytes -- if True (default), use multiples of 1024
if False, use multiples of 1000
Returns: string
"""
if size < 0:
raise ValueError('number must be non-negative')
multiple = 1024 if a_kilobyte_is_1024_bytes else 1000
for suffix in SUFFIXES[multiple]:
size /= multiple
if size < multiple:
return '{0:.1f} {1}'.format(size, suffix)
raise ValueError('number too large')
if __name__ == '__main__': # pragma: no cover
print(approximate_size(1000000000000, False))
print(approximate_size(1000000000000))
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

18
labs/L14/test_client.py Normal file
View File

@ -0,0 +1,18 @@
import pytest
from client import approximate_size
def test_1kb():
assert approximate_size(1_000) == "1.0 KB"
def test_100mb():
assert approximate_size(100_000_000) == "100.0 MB"
def test_1gb():
assert approximate_size(1_000_000_000) == "1.0 GB"
def test_docstring():
assert approximate_size.__doc__ is not None

10
labs/L14/test_divisive.py Normal file
View File

@ -0,0 +1,10 @@
from divisive import fraction
import math
def test_fraction_int():
assert fraction(4, 2) == 2
def test_fraction_NaN():
assert math.isnan(fraction(4, 0))

View File

@ -0,0 +1,20 @@
import pytest
from humansize import approximate_size
def test_1000():
assert approximate_size(1000000000000, False) == "1.0 TB"
def test_1024():
assert approximate_size(1000000000000) == "931.3 GiB"
def test_negative():
with pytest.raises(ValueError):
approximate_size(-1)
def test_huge_number():
with pytest.raises(ValueError):
approximate_size(1_000_000_000_000_000_000_000_000_000_000)