Skip to content

Commit

Permalink
Simplify and remove unnecessary files for the assignment (#7)
Browse files Browse the repository at this point in the history
* Remove `main` interpreter runner

We remove the top-level main because we really only need testing.

* Remove autograding workflow

* Remove autograding workflow

* Update build and .gitignore

* Remove grader and util files

* Remover file-based tester

* Standardize locations to **/jsy/lab1

* Clean up student files

- Remove extra interfaces
- Remove external test files
- Add more comments

* Add .scalafmt.conf

* Update build.sbt
  • Loading branch information
bechang authored Sep 7, 2024
1 parent 76bddbf commit 1d42143
Show file tree
Hide file tree
Showing 27 changed files with 475 additions and 1,050 deletions.
56 changes: 0 additions & 56 deletions .github/workflows/autograding.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/sbt-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# This is a basic workflow to help you get started with Actions

name: sbt test

# Controls when the workflow will run
Expand Down
24 changes: 21 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
.idea
# sbt
target/
project/target/
project/project/
project/target/*
project/project/*
.ivy2
.sbt

# Intellj
.idea

# VS Code
.vscode

# Metals
.metals
.bloop
metals.sbt
.bsp

# Ammonite
.ammonite

# macOS
.DS_Store
2 changes: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "3.7.15"
runner.dialect = scala213
11 changes: 5 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name := "pppl-lab1"

lazy val commonSettings = Seq(
organization := "edu.colorado.cs",
version := "3.4.4",
version := "4.0.0",

scalaVersion := "2.13.6",
scalaVersion := "2.13.14",
scalacOptions ++= Seq(
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-feature", // Emit warning for features that should be imported explicitly
Expand All @@ -14,12 +14,10 @@ lazy val commonSettings = Seq(
"-Ywarn-extra-implicit", // more than one implicit parameter section is defined
"-Xlint:nullary-unit", // nullary methods return Unit
"-Xlint:inaccessible", // inaccessible types in method signatures
"-Xlint:nullary-override", // non-nullary def f() overrides nullary def f
"-Xlint:infer-any", // a type argument is inferred to be Any
"-Xlint:missing-interpolator", // literal appears to be missing an interpolator id
"-Xlint:option-implicit", // apply used implicit view
"-Xlint:package-object-classes", // object defined in package object
"-Xlint:unsound-match", // may not be typesafe
"-Xlint:stars-align", // wildcard must align with sequence component
"-Xlint:constant", // a constant arithmetic expression results in an error
//"-Xfatal-warnings", // turn warnings into errors
Expand All @@ -33,8 +31,9 @@ lazy val commonSettings = Seq(
),

// set logging to show only errors during runs
logLevel in run := Level.Error,
logLevel in runMain := Level.Error,
logLevel / run := Level.Error,
logLevel / runMain := Level.Error,
Global / excludeLintKeys += logLevel,

// JVM arguments: 8G heap size, 2M stack size
//javaOptions in Test += "-Xmx8G -Xss2M",
Expand Down
Binary file removed lab1.pdf
Binary file not shown.
6 changes: 0 additions & 6 deletions lab1.sh

This file was deleted.

44 changes: 0 additions & 44 deletions node/jsy.js

This file was deleted.

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.5.2
sbt.version=1.10.1
109 changes: 109 additions & 0 deletions src/main/scala/jsy/lab1/Lab1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package jsy.lab1

object Lab1 {
/*
* CSCI 3155: Lab 1
* <Your Name>
*
* Partner: <Your Partner's Name>
* Collaborators: <Any Collaborators>
*/

/*
* Fill in the appropriate portions above by replacing things delimited
* by '<'... '>'.
*
* Replace the '???' expression with your code in each function. The
* '???' expression is a Scala expression that throws a NotImplementedError
* exception.
*
* Your lab will not be graded if it does not compile.
*
* This template compiles without error. Before you submit comment out any
* code that does not compile or causes a failing assert. Simply put in a
* '???' as needed to get something that compiles without error.
*/

/*
* Example: Test-driven development of `plus`
*
* A convenient, quick-and-dirty way to experiment, especially with small code
* fragments, is to use the interactive Scala interpreter. The simplest way
* to use the interactive Scala interpreter is through a worksheet, such as
* Lab1.worksheet.sc. A Scala Worksheet is code evaluated in the context of
* the project with results for each expression shown inline (somewhat like a
* Jupyter notebook).
*
* Step 0: Sketch an implementation in Lab1.scala using ??? for unimplemented things.
* Step 1: Do some experimentation in Lab1.worksheet.sc.
* Step 2: Write a test in Lab1Spec.scala, which should initially fail because of the ???.
* Step 3: Fill in the ??? here to finish the implementation to make your test pass.
*/

//def plus(x: Int, y: Int): Int = ???
def plus(x: Int, y: Int): Int = 0
// def plus(x: Int, y: Int): Int = x + y

/* Exercises */

def repeat(s: String, n: Int): String = ???

def sqrtStep(c: Double, xn: Double): Double = ???

def sqrtN(c: Double, x0: Double, n: Int): Double = ???

def sqrtErr(c: Double, x0: Double, epsilon: Double): Double = ???

def sqrt(c: Double): Double = {
require(c >= 0)
if (c == 0) 0 else sqrtErr(c, 1.0, 0.0001)
}

/* Search Tree */

sealed abstract class Tree
case object Empty extends Tree
case class Node(l: Tree, d: Int, r: Tree) extends Tree

def repOk(t: Tree): Boolean = {
def check(t: Tree, min: Int, max: Int): Boolean = t match {
case Empty => true
case Node(l, d, r) => ???
}
check(t, Int.MinValue, Int.MaxValue)
}

def insert(t: Tree, n: Int): Tree = ???

def deleteMin(t: Tree): (Tree, Int) = {
require(t != Empty)
(t: @unchecked) match {
case Node(Empty, d, r) => (r, d)
case Node(l, d, r) =>
val (l1, m) = deleteMin(l)
???
}
}

def delete(t: Tree, n: Int): Tree = ???

/* Evaluate the JavaScripty Calculator Language */

/* We import `jsy.lab1.ast._` so that we can make use of the Expr type defined
* there. Take a look at ast.scala to see what the Expr type looks like, as well
* some helper functions for defining values (`isValue`) and pretty-printing
* (`pretty`) that you are welcome to use.
*/
import jsy.lab1.ast._

def eval(e: Expr): Double = e match {
case N(n) => ???
case _ => ???
}

/* We also overload `eval` to take a String and parse it into an Expr and then
* evaluate it using your `eval` function defined above.
*/
def eval(e: String): Double = eval(Parser.parse(e))

}
76 changes: 76 additions & 0 deletions src/main/scala/jsy/lab1/Lab1.worksheet.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* CSCI 3155: Lab 1 Worksheet
*
* This worksheet demonstrates how you could experiment
* interactively with your implementations in Lab1.scala.
*/

/*
* Example: Test-driven development of `plus`
*/

/* Here we can write expressions to experiment with how we might implement
* something. The expression is evaluated interactively.
*/
1 + 1
val n = 1 + 1
n + 3

/* The worksheet is built with all of the project files, so we can call
* a function from your `jsy.lab1.Lab1` object (in Lab1.scala).
*/
//jsy.lab1.Lab1.plus(3, 4)

/* We can imports all of the functions from your `jsy.lab1.Lab1` object. */
import jsy.lab1.Lab1._
//plus(3, 4)

/* We can check the implementation here, though it better to write tests
* in Lab1Spec.scala.
*/
//assert(plus(1, 1) == 2)

/* Braces {} can be used wherever parentheses () can be (but not the other
* way around). Braces {} introduce scope, while () do not.
*/
// assert {
// val two = 2
// plus(1, 1) == two
// }

/* Exercises */

//assert(repeat("a", 3) == "aaa")

/* We import jsy.lab.ast._ to use the AST nodes. */
import jsy.lab1.ast._

/* A parser defines how to translate concrete syntax (i.e., strings a programmer types)
* into an abstract syntax tree (AST) that we use to evaluate the program. A parser
* is given to you in jsy.lab1.Parser. You can use the parser to parse a String into
* an Expr.
*
* Here are some shortcuts to that parser for your reference.
* */
import jsy.lab1.Parser
def parse(s: String): Expr = Parser.parse(s)
def parseFile(filename: String): Expr = Parser.parseFile(filename)

/* Call the parser (from the provided library) on a string */
parse("-4")

val negFourAST = parse("-4")
assert {
negFourAST match {
case Unary(_, _) => true
case _ => false
}
}

/* Evaluate that `negFourAST` expression. */
//eval(negFourAST)

/* For convenience, we also have an overloaded `jsy.lab1.Lab1.eval` function that takes
* a String, calls the parser, and then delegates to your `eval` function.
*/
//eval("1 + 1")
Loading

0 comments on commit 1d42143

Please sign in to comment.