Skip to content

Instantly share code, notes, and snippets.

View irfanhanif's full-sized avatar

Irfan Hanif irfanhanif

  • Mapan PT RUMA (Gojek Group)
  • Jakarta
View GitHub Profile
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
)
type ShoppingRecord struct {
@irfanhanif
irfanhanif / person.go
Last active February 3, 2022 03:28
Unexpected Side Effect
package entity
type Person struct {
name string
age int
profImg []byte
}
func NewPerson(name string, age int, profimg []byte) *Person {
return &Person{
@irfanhanif
irfanhanif / main.go
Created February 3, 2022 03:19
Failed Encapsulation
package main
import (
"fmt"
"gitlab.mapan.io/irfanhanif/playground/entity"
)
func main() {
p := entity.NewPerson("Arhan Nadeo", 23, []byte(`sebuah gambar`))
@irfanhanif
irfanhanif / person.go
Last active February 4, 2022 10:09
An Encapsulated Struct
package entity
type Person struct {
name string
age int
profImg []byte // potensi size besar di sini
}
func NewPerson(name string, age int, profimg []byte) *Person {
return &Person{
@irfanhanif
irfanhanif / main.go
Created February 3, 2022 03:08
Pass by Reference with Unexported Fields
package main
import (
"fmt"
"github.com/irfanhanif/playground/entity"
)
func main() {
p := entity.NewPerson("Arhan Nadeo", 23, []byte(`sebuah gambar`))
@irfanhanif
irfanhanif / pass_by_value.go
Created February 3, 2022 02:53
Example of Pass by Value
package main
import "fmt"
type Person struct {
Name string
Age int
}
func main() {
@irfanhanif
irfanhanif / return_by_parameter.go
Last active February 2, 2022 15:33
Example of Return by Parameter
package main
import "fmt"
type Person struct {
Name string
Age int
}
func main() {
Code.require_file("ex_unit_extended.ex", __DIR__)
defmodule AppleBasketTest do
use ExUnit.Case
use ExUnitExtended
test "add_apple/1 add apple to a basket" do
given__(:an_apple_basked_that_consists_of_2_apples_with_maximum_capacity_of_5_apples)
|> when__(:i_add_1_apple_to_the_basket)
|> then__("The basket should have", :total_of_3_apples_in_the_basket)
Code.require_file("ex_unit_extended.ex", __DIR__)
defmodule AppleBasketTest do
use ExUnit.Case
use ExUnitExtended
test "add_apple/1 add apple to a basket" do
given__(:an_apple_basked_that_consists_of_2_apples_with_maximum_capacity_of_5_apples)
|> when__(:i_add_1_apple_to_the_basket)
|> then__("The basket should have", :total_of_3_apples_in_the_basket)
@irfanhanif
irfanhanif / ex_unit_extended.ex
Created November 19, 2019 10:41
Customized ex unit
defmodule ExUnitExtended do
defmacro __using__(_) do
quote do
def given__(given_function_name) do
apply(__MODULE__.Given, given_function_name, [])
end
def when__(data_from_given_statement, test_function_name) do
apply(__MODULE__.When, test_function_name, [data_from_given_statement])
end