Skip to content

Commit

Permalink
Refctor LA01
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-byrne committed Oct 15, 2024
1 parent 9b84558 commit 67f1999
Show file tree
Hide file tree
Showing 36 changed files with 68 additions and 36 deletions.
32 changes: 32 additions & 0 deletions ...rge_assignment_01/large_assignment_01.sml → src/la1/la1.sml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


(*
* 1
* Type: `int * int * int -> bool`
* Desc: The triangle inequality theorem states that the sum of any
* two sides of a triangle must be greater than or equal to the
Expand All @@ -22,6 +23,7 @@ fun triangle(0, _, _) = false


(*
* 2
* Type: `real * real * real -> bool`
* Desc: The triangle inequality theorem states that the sum
* of any two sides of a triangle must be greater than
Expand All @@ -41,6 +43,7 @@ fun triangleR(a, b, c) =


(*
* 3
* Type: `int * 'a list -> 'a list`
* Desc: Given an integer n and a list l, cycle n elements
* from the list to the end of the list. You can assume
Expand All @@ -54,6 +57,7 @@ fun triangleR(a, b, c) =


(*
* 4
* Type: `'a list -> 'a list`
* Desc: Mirror the list. You may not use any reverse function
* (even as a helper function).
Expand All @@ -65,6 +69,7 @@ fun triangleR(a, b, c) =


(*
* 5
* Type: `int list * int -> int list`
* Desc: Take a list l and an integer n and return a list that
* contains all the elements in l that are greater than
Expand All @@ -75,6 +80,7 @@ fun triangleR(a, b, c) =


(*
* 6
* Type: `''a list * ''a list -> bool`
* Desc: Return true if the first list is a suffix of the
* second list and false otherwise. Do not reverse
Expand All @@ -101,6 +107,7 @@ fun suffix([], _) = true


(*
* 7
* Type: `'a list * int → 'a`
* Desc: This function takes a list and an integer i and
* returns the ith element in the list. Start the
Expand All @@ -112,6 +119,7 @@ fun get([], _) = raise Empty


(*
* 8
* Type: `'a list * int * int → 'a list`
* Desc: This function takes a list and two integers i and j
* and returns a subList that includes everything from
Expand All @@ -137,13 +145,15 @@ fun subList([], _, _) = []


(*
* 9
* Type: `'a list → 'a list`
* Desc: Reverse the list without using append
*)
fun reverse li = foldl (fn(cur, acc) => cur::acc) [] li;


(*
* 10
* Type: `'a list * ('a → 'b) → 'b list`
* Desc: Apply a function to a list of elements. You may not
* use map, foldr, or foldl.
Expand All @@ -156,6 +166,7 @@ fun apply([], f) = []


(*
* 11
* Type: `'a list * 'b * ('a * 'b → 'b) → 'b`
* Desc: Take a list, a starting value, and a function and
* collapse the list down using the function. You may
Expand All @@ -170,6 +181,7 @@ fun collapse([], startVal, f) = startVal


(*
* 12
* Type: `('a * 'a → bool) → 'a list → 'a list`
* Desc: Sort a list using the quicksort method, but make it
* general enough so that you can pass in a function and
Expand All @@ -190,6 +202,7 @@ fun quicksort f [] = []


(*
* 13
* Type: `('a * 'a → bool) → 'a list → 'a list`
* Desc: Sort a list using the bubble sort method, but make it
* general enough so that you can pass in a function and
Expand All @@ -215,6 +228,7 @@ fun bubbleSort f [] = []


(*
* 14
* Type: `('a * 'a → bool) → 'a list → 'a list`
* Desc: Sort a list using the insertion sort method, but make it
* general enough so that you can pass in a function and
Expand All @@ -232,6 +246,7 @@ fun insertionSort f [] = []


(*
* 15
* Type: `string → string → bool`
* Desc: Determine if a string is a substring of another
* string.
Expand All @@ -257,6 +272,7 @@ fun substring "" "" = true


(*
* 16
* Type: `'a → 'a list → int`
* Desc: Determine the index of the first occurrence of a value in a list.
* Indexing should start at 0.
Expand All @@ -277,6 +293,7 @@ fun indexOf target li =


(*
* 17
* Type: `int → int → string`
* Desc: Turn a decimal number into a string representation of base N.
* The input for N will be an integer between 2 and 10 (inclusive).
Expand All @@ -300,6 +317,7 @@ fun dec2BaseN base n =


(*
* 18
* Type: `int → 'a list → 'a list`
* Desc: Drop every nth element in a list.
*)
Expand All @@ -320,6 +338,7 @@ fun dropNth _ [] = []


(*
* 19
* Type: `'a list list → 'a list`
* Desc: Takes a list of lists and flattens it so that it is
* now just a single list of elements. It should contain
Expand All @@ -331,6 +350,7 @@ fun flatten li = foldr (fn(cur, acc) => cur @ acc) [] li;


(*
* 20
* Type: `('a * 'b → 'b) → 'b → 'a list list → 'b list`
* Desc: Take a list of lists, a function, and a starting
* value. Apply the function recursively to each list,
Expand All @@ -342,6 +362,7 @@ fun condenseLists f startVal li = foldr (fn(cur, acc) => collapse(cur, startVal,


(*
* 21
* Type: `('a → bool) → 'a list → 'a list`
* Desc: Remove all the elements from a list for which the
* given function returns true. This should be a
Expand All @@ -351,6 +372,7 @@ fun remove f li = foldr (fn(cur, acc) => if f(cur) then acc else cur::acc) [] li


(*
* 22
* Type: `'a list → 'a list`
* Desc: Take a list and create a new list where every element
* is repeated three times. Do not use append.
Expand All @@ -359,6 +381,7 @@ fun triplist li = foldr (fn(cur, acc) => cur::cur::cur::acc) [] li;


(*
* 23
* Type: `'a list → int → 'a list`
* Desc: Take a list l and an integer n and create a list that
* repeats l n times.
Expand All @@ -368,6 +391,7 @@ fun repeat li 0 = []


(*
* 24
* Type: `'a list → ('a → bool) → ('a → 'a) → 'a list`
* Desc: Takes a list l, a function f, and a function g. It
* then returns a list where all the elements in l for
Expand All @@ -378,6 +402,7 @@ fun filterApply li f g = foldr (fn(cur, acc) => if f(cur) then g(cur)::acc else


(*
* 25
* Type: `int → int → int → int list`
* Desc: Given three integers (a, d, and l), create a
* list of length l that contains an arithmetic
Expand All @@ -390,6 +415,7 @@ fun arithSeq a d 0 = []


(*
* 26
* Type: `'a → 'a list → bool`
* Desc: Return true if the element is in the list,
* false otherwise.
Expand All @@ -399,6 +425,7 @@ fun element x [] = false


(*
* 27
* Type: `'a list → bool`
* Desc: Return true if the list is a set, meaning that
* it has no duplicate values. Return false
Expand All @@ -409,6 +436,7 @@ fun isSet([]) = true


(*
* 28
* Type: `'a list * 'a list → 'a list`
* Desc: Combine two lists, which you can assume are
* sets, to produce the union of the two sets. The
Expand All @@ -421,6 +449,7 @@ fun union([], []) = []


(*
* 29
* Type: `'a list * 'a list → 'a list`
* Desc: Combine two lists, which you can assume are
* sets, to produce the intersection of the two
Expand All @@ -437,6 +466,7 @@ fun intersection(li1, li2) =


(*
* 30
* Type: `'a list * 'a list → 'a list`
* Desc: Combine two lists, which you can assume are
* sets, to produce the difference of the two sets
Expand All @@ -449,6 +479,7 @@ fun difference([], _) = []


(*
* 31
* Type: `'a list * 'a list → 'a list`
* Desc: Combine two lists, which you can assume are
* sets, to produce the xor of the two sets (i.e.
Expand All @@ -460,6 +491,7 @@ fun xor(li1, li2) = union(difference(li1, li2), difference(li2, li1));


(*
* 32
* Type: `'a list → 'a list list`
* Desc: Given a list that you can assume is a set,
* return the powerset of the set (i.e. the set of
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test-la-01.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#
#./test --rootdir tests/tests-large_assignment_01 --failed-first --log-cli-level WARNING $@
./test --rootdir tests/tests-large_assignment_01 --nl --log-cli-level INFO
#./test --rootdir tests/tests-la1 --failed-first --log-cli-level WARNING $@
./test --rootdir tests/tests-la1 --nl --log-cli-level INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

val testCasesApplyInt = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Test cases for arithSeq *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Integer Test Cases *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

val testCasesCollapseInt = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Test cases for integer lists *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

val testCycle = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Test cases for the dec2BaseN function *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Helper function to compare lists as sets (order doesn't matter) *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Integer List Test Cases *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Test cases for integer lists *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Helper function to append "x" to a string *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Test cases for integer lists *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

val testCasesGetInt = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

val testCasesGtList = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Test cases for the indexOf function *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Integer Test Cases *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* Large Assignment 01 Tests *)

use "src/large_assignment_01/large_assignment_01.sml";
use "src/la1/la1.sml";
use "tests/utils.sml";

(* Helper function to compare lists as sets (order doesn't matter) *)
Expand Down
Loading

0 comments on commit 67f1999

Please sign in to comment.