This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("business logic should not depend on the frontend", async ()=> { | |
const rule = filesOfProject() | |
.inFolder("business") | |
.shouldNot() | |
.dependOnFiles() | |
.inFolder("frontend") | |
await expect(rule).toPassAsync() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void PublicMethodTests() | |
{ | |
var publicMethods = | |
MethodMembers().That().ArePublic() | |
.And().AreNotConstructors() | |
.And().AreNotDeclaredIn(Interfaces()) | |
.As("implemented public methods"); | |
var rule = publicMethods.Should() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void ServicesShouldBeAuthorized() | |
{ | |
var services = Classes().That() | |
.DependOnAny(typeof(ServerCallContext)) | |
.And().AreNotAbstract() | |
.As("Services"); | |
var rule = services | |
.Should() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final JavaClasses classes = new ClassFileImporter().importPackages("com.tngtech.archunit.example.layers"); | |
@Test | |
public void layer_dependencies_are_respected() { | |
layeredArchitecture() | |
.layer("Controllers").definedBy("..controller..") | |
.layer("Services").definedBy("..layers.service..") | |
.layer("Persistence").definedBy("..layers.persistence..") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insertionSort(xs : List[Int]) : List[Int] = { | |
xs match{ | |
case Nil => Nil | |
case x :: xs1 => insert(x, isort(xs1)) | |
} | |
} | |
def insert(x : Int, xs : List[Int]) : List[Int] = { | |
xs match { | |
case Nil => List(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mergeSort(xs: List[Int]): List[Int] = { | |
val n = xs.length / 2 | |
if (n == 0) xs | |
else { | |
val (firstHalf, secondHalf) = xs splitAt n | |
merge(mergeSort(firstHalf), mergeSort(secondHalf)) | |
} | |
} | |
def merge(xs: List[Int], ys: List[Int]): List[Int] = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package patmat | |
/** | |
* A huffman code is represented by a binary tree. | |
* | |
* Every `Leaf` node of the tree represents one character of the alphabet that the tree can encode. | |
* The weight of a `Leaf` is the frequency of appearance of the character. | |
* | |
* The branches of the huffman tree, the `Fork` nodes, represent a set containing all the characters | |
* present in the leaves below it. The weight of a `Fork` node is the sum of the weights of these |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait List[T] { | |
def isEmpty:Boolean | |
def head: T | |
def tail: List[T] | |
} | |
class Cons[T] (val head: T, val tail: List[T]) extends List[T] { | |
def isEmpty = false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 2. Purely Functional Sets. | |
*/ | |
trait FunSets { | |
/** | |
* We represent a set by its characteristic function, i.e. | |
* its `contains` predicate. | |
*/ | |
override type FunSet = Int => Boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here is how I would curry a product function. I really like the word curry, btw. | |
def product(f: Int => Int)(a: Int, b: Int): Int = | |
if (a > b) 1 else f(a) * product(f)(a + 1, b) | |
// Factorial can now be written as follows | |
// Because factorial is by definition the product of all numbers 1 to n | |
def factorial(n: Int) = product(identity)(1, n) | |
// True! | |
factorial(5) == 120 |
NewerOlder