Skip to content

Instantly share code, notes, and snippets.

import unittest
# Use the imports below to test either your array-based stack
# or your link-based version
from stack_array import Stack
# from stack_linked import Stack
class TestLab2(unittest.TestCase):
def test_simple(self):
"""Test simple stack operations"""
import unittest
# from queue_array import Queue
from queue_linked import Queue
class TestLab1(unittest.TestCase):
def test_queue(self):
'''Trivial test to ensure method names and parameters are correct'''
q = Queue(5)
q.is_empty()
q.is_full()
# Start of unittest - add to completely test functions in exp_eval
import unittest
from exp_eval import *
class test_expressions(unittest.TestCase):
def test_postfix_eval_addition(self):
"""Test subtraction with postfix_eval"""
self.assertAlmostEqual(postfix_eval("3 5 +"), 8)
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
Plug 'scrooloose/nerdcommenter'
call plug#end()
if !has('gui_running')
set t_Co=256
endif
set laststatus=2
syntax on
import unittest
from sorts import *
class TestLab4(unittest.TestCase):
def test_simple(self):
"""Simple test for selection sort"""
nums = [23, 10]
comps = selection_sort(nums)
self.assertEqual(comps, 1)
import unittest
import random
from heap import *
class TestHeap(unittest.TestCase):
def test_01_enqueue(self):
"""Test simple enqueue operations and build heap"""
test_heap = MaxHeap(7)
test_heap.build_heap([2, 9, 7, 6, 5, 8])
insert = test_heap.enqueue(10)
import unittest
from hash_quad import *
class TestList(unittest.TestCase):
def test_01a(self):
ht = HashTable(7)
self.assertEqual(ht.get_table_size(), 7)
def test_01b(self):
import unittest
import filecmp
from concordance import *
class TestList(unittest.TestCase):
def test_01(self):
conc = Concordance()
conc.load_stop_table("stop_words.txt")
conc.load_concordance_table("file1.txt")
@mcclane
mcclane / gist:24ebc184f3d9c6a8c6f6fbcc92f6c972
Last active October 17, 2020 23:29
possible let desugaring
;; Turn an s-expression in to an AST using the ExpressionC elements defined above.
(define (parse [expression : Sexp]) : ExprC
(match expression
[(? real? value) (numC (realV value))]
[(list 'ifleq0 condition if-block else-block)
(ifleq0C (parse condition) (parse if-block) (parse else-block))]
[(? symbol? value) (idC value)]
[(list 'fn (list (? symbol? arguments) ...) body) (lambdaC (cast arguments (Listof Symbol)) (parse body))]
[(list 'let (? list? arguments) ... 'in (? list? body))
(appC (lambdaC (get-let-arg-symbols (cast arguments (Listof Sexp))) (parse body))
;; Test parse
(check-equal? (parse 10) (vc 10))
(check-equal? (parse -10) (vc -10))
(check-equal? (parse '{+ 10 5}) (appC (idC '+) (list (valueC (realV 10)) (valueC (realV 5)))))
(check-equal? (parse '{+ 10 {+ 2 3}}) (appC (idC '+) (list (valueC (realV 10)) (appC (idC '+)
(list (valueC (realV 2))
(valueC (realV 3)))))))
(check-equal? (parse '{* 10 5}) (appC (idC '*) (list (valueC (realV 10)) (valueC (realV 5)))))
(check-equal? (parse '{* 10 {+ 2 3}}) (appC (idC '*) (list (valueC (realV 10)) (appC (idC '+)
(list (valueC (realV 2))