Skip to content

Instantly share code, notes, and snippets.

View chelseatroy's full-sized avatar

Chelsea Troy chelseatroy

View GitHub Profile
@chelseatroy
chelseatroy / test_keyValueStore.py
Created December 24, 2019 15:28
assert_on_file improved
...
def assert_on_file(self, path, length, lines):
with open(path, "r") as file:
lines = file.read().splitlines()
assert len(lines) == length
for index, line in enumerate(lines):
assert lines[index] == line
@chelseatroy
chelseatroy / test_keyValueStore.py
Created December 24, 2019 15:27
assert_on_file
...
def assert_on_file(self, path, length, lines):
with open(path, "r") as file:
lines = file.read().split("\n")
assert len(lines) == length
for index, line in enumerate(lines):
assert lines[index] == line
self = <tests.test_keyValueStore.TestKeyValueStore object at 0x10d80f0f0>
path = 'tests/test_kvs_logs.txt', length = 1
lines = ['set Sibyl cruelty', '']
def assert_on_file(self, path, length, lines):
with open(path, "r") as file:
lines = file.read().split("\n")
> assert len(lines) == length
E AssertionError: assert 2 == 1
E + where 2 = len(['set Sibyl cruelty', ''])
@chelseatroy
chelseatroy / KeyValueStore.py
Last active December 24, 2019 15:06
key_value_store.py
class KeyValueStore:
...
def write_to_log(self, string_operation, path_to_logs=''):
if path_to_logs == '':
path_to_logs = "logs/" + self.server_name + "_log.txt"
f = open(path_to_logs, "a+")
f.write(string_operation + '\n')
f.close()
@chelseatroy
chelseatroy / test_keyValueStore.py
Last active December 24, 2019 15:07
Unit Test Example
from src.key_value_store import KeyValueStore
TEST_LOG_PATH = "tests/test_kvs_logs.txt"
class TestKeyValueStore():
...
def test_write_to_log(self):
self.clean_up_file(TEST_LOG_PATH)
@chelseatroy
chelseatroy / traffic_system.py
Last active December 23, 2019 20:07
Storing State
import time
from threading import Event, Thread
import queue
class TrafficLight:
def __init__(self, name, state):
self.name = str(name)
self.current_state = state
def progress(self):
@chelseatroy
chelseatroy / traffic_light.py
Created December 17, 2019 18:58
Storing State
class TrafficLight:
def __init__(self, name, state):
self.name = str(name)
self.current_state = state
def progress(self):
if self.current_state == "green":
print(self.name + " light yellow")
self.current_state = "yellow"
elif self.current_state == "yellow":
@chelseatroy
chelseatroy / traffic_light.py
Created December 17, 2019 18:57
Storing States as Dictionaries
#Initial state of traffic light
Init = {
'out1': 'G',
'out2': 'R',
'clock': 0,
'button': False,
'pc': 'G1'
}
# Define functions that determine state membership and state update.
@chelseatroy
chelseatroy / amb.scm
Created November 16, 2019 21:54
require procedure
(try '(define (require predicate) (if predicate #t (amb))) env)
@chelseatroy
chelseatroy / amb.scm
Created November 16, 2019 20:18
Order in Amb Evaluator
(try '(define (a-number-between low-number high-number)
(if (= low-number high-number)
low-number
(amb low-number (a-number-between (+ low-number 1) high-number))
)
) env)
(try '(a-number-between 1 9) env) ; --> 1
(try '(a-number-between 1 9) env) ; --> 1
(try '(a-number-between 1 9) env) ; --> 1