From 6a31db8470631246e4553157d0a0159902ffc78c Mon Sep 17 00:00:00 2001 From: Krasilnikov Roman Date: Thu, 4 Jul 2024 12:17:42 +0300 Subject: [PATCH] Simplify go test case --- .../src/content/design-patterns/factory/go/code.go | 12 ++++++------ .../content/design-patterns/factory/go/factory.ts | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/ppp/src/content/design-patterns/factory/go/code.go b/apps/ppp/src/content/design-patterns/factory/go/code.go index 9648350..9ea857a 100644 --- a/apps/ppp/src/content/design-patterns/factory/go/code.go +++ b/apps/ppp/src/content/design-patterns/factory/go/code.go @@ -1,13 +1,13 @@ -package factory +package payment -type PaymentSystemType string +type SystemType int const ( - PayPal PaymentSystemType = "paypal" - WebMoney PaymentSystemType = "webmoney" - CatBank PaymentSystemType = "cat-bank" + PayPal SystemType = iota + WebMoney + CatBank ) -func Payment(tp PaymentSystemType, base int, amount int) int { +func Payment(tp SystemType, base int, amount int) int { panic("Not implemented") } diff --git a/apps/ppp/src/content/design-patterns/factory/go/factory.ts b/apps/ppp/src/content/design-patterns/factory/go/factory.ts index 6a27760..c107070 100644 --- a/apps/ppp/src/content/design-patterns/factory/go/factory.ts +++ b/apps/ppp/src/content/design-patterns/factory/go/factory.ts @@ -5,14 +5,20 @@ import type { UniversalFactory } from "testing/actor"; import type { GoUniversalFactoryData } from "@/lib/workers/go"; import type { Input, Output } from "../tests-data"; +import type { PaymentSystemType } from "../reference"; export const factory: UniversalFactory< Input, Output, GoUniversalFactoryData > = ({ makeTestRunnerFactory }) => { + const GO_PAYMENT_SYSTEM_TYPES: Record = { + paypal: 0, + webmoney: 1, + "cat-bank": 2, + }; return makeTestRunnerFactory( ({ paymentSystem, amount, base }) => - `factory.Payment(factory.PaymentSystemType("${paymentSystem}"), ${base}, ${amount})` + `payment.Payment(payment.SystemType(${GO_PAYMENT_SYSTEM_TYPES[paymentSystem]}), ${base}, ${amount})` ); };