examples

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2020 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ItemTypeLuxury is a labels as Luxury item
	ItemTypeLuxury = "LUXURY"
	// ItemTypeNormal is a labels as Non Luxury item
	ItemTypeNormal = "NORMAL"
)

Variables

View Source
var (
	// PriceCheckRule1 is a rule definition for test.
	PriceCheckRule1 = `` /* 236-byte string literal not displayed */

	// PriceCheckRule2 is a rule definition for test.
	PriceCheckRule2 = `` /* 270-byte string literal not displayed */

)
View Source
var (
	// Purchases contains list of purchases to be evaluated.
	Purchases = []*Purchase{
		&Purchase{
			PurchaseDate: time.Date(2019, time.January, 4, 13, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.January, 17, 15, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.February, 12, 7, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.February, 24, 3, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.March, 22, 22, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.March, 24, 17, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.March, 15, 14, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.March, 25, 10, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.March, 19, 13, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.June, 6, 21, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
		&Purchase{
			PurchaseDate: time.Date(2019, time.June, 19, 22, 0, 0, 0, time.Local),
			ItemType:     ItemTypeLuxury,
			Price:        100000,
		},
	}
)

Functions

This section is empty.

Types

type CashFlow

type CashFlow struct {
	TotalPurchases    float64
	PurchaseCount     int
	TotalTax          float64
	PurchasesAfterTax float64
}

CashFlow stores simulated cash flow

func (*CashFlow) String

func (cf *CashFlow) String() string

String shows a cash flow.

type CashFlowCalculator

type CashFlowCalculator struct {
}

CashFlowCalculator to simulate a calculator

func (*CashFlowCalculator) CalculatePurchases

func (cf *CashFlowCalculator) CalculatePurchases()

CalculatePurchases will calculate a speciffic purchase by rule engine.

type Item

type Item struct {
	Name     string
	Price    int64
	Discount int64
}

Item store item definition.

type ItemCart

type ItemCart struct {
	Items []*Item
}

ItemCart simulates a shopping cart.

func (*ItemCart) CountItemWithPriceAboveWithNoDiscount

func (cart *ItemCart) CountItemWithPriceAboveWithNoDiscount(minimumPrice int64) int

CountItemWithPriceAboveWithNoDiscount will count items in a cart that have some minimum price

func (*ItemCart) GiveDiscountForItemPriceAbove

func (cart *ItemCart) GiveDiscountForItemPriceAbove(minimumPrice int64, discount int64)

GiveDiscountForItemPriceAbove will apply discount to items that have some minimum price.

func (*ItemCart) ShowDiscount

func (cart *ItemCart) ShowDiscount()

ShowDiscount will print out each discounted items.

type ItemPriceChecker

type ItemPriceChecker struct {
}

ItemPriceChecker serve a checker object

func (*ItemPriceChecker) CheckCart

func (cf *ItemPriceChecker) CheckCart()

CheckCart will execute cart checking.

func (*ItemPriceChecker) CheckPrices

func (cf *ItemPriceChecker) CheckPrices()

CheckPrices will test the rule to check item prices.

type MyPoGo

type MyPoGo struct {
}

MyPoGo serve as example plain Plai Old Go Object.

func (*MyPoGo) Compare

func (p *MyPoGo) Compare(t1, t2 string) bool

Compare will compare the equality between the two string.

func (*MyPoGo) GetStringLength

func (p *MyPoGo) GetStringLength(sarg string) int

GetStringLength will return the length of provided string argument

type Purchase

type Purchase struct {
	PurchaseDate time.Time
	ItemType     string
	Price        float64

	Tax             float64
	PriceAfterTax   float64
	IgnoredPurchase bool
}

Purchase stores a purchasing example

type User

type User struct {
	Name string
	Age  int
	Male bool
}

User is an example user struct.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL