Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Susana RyanSusana

View GitHub Profile
View businessLogicTest.js
it("business logic should not depend on the frontend", async ()=> {
const rule = filesOfProject()
.inFolder("business")
.shouldNot()
.dependOnFiles()
.inFolder("frontend")
await expect(rule).toPassAsync()
})
View publicMethodTest.cs
[Test]
public void PublicMethodTests()
{
var publicMethods =
MethodMembers().That().ArePublic()
.And().AreNotConstructors()
.And().AreNotDeclaredIn(Interfaces())
.As("implemented public methods");
var rule = publicMethods.Should()
View securedTest.cs
[Test]
public void ServicesShouldBeAuthorized()
{
var services = Classes().That()
.DependOnAny(typeof(ServerCallContext))
.And().AreNotAbstract()
.As("Services");
var rule = services
.Should()
@RyanSusana
RyanSusana / layeredTest.java
Last active Dec 1, 2021
Layered Architecture Test
View layeredTest.java
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..")
View isort.scala
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)
View msort.scala
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] =
View huffman.scala
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
View list.scala
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;
}
View functionalSets.scala
/**
* 2. Purely Functional Sets.
*/
trait FunSets {
/**
* We represent a set by its characteristic function, i.e.
* its `contains` predicate.
*/
override type FunSet = Int => Boolean
View newFactorial.scala
// 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