Skip to content

Commit

Permalink
Create go.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
siyanew authored and Siyanew committed Jul 17, 2023
1 parent 7cd9b7e commit bdf3707
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Test
run: go test -v ./...
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
![Test](https://github.com/siyanew/num2fa/actions/workflows/test.yml/badge.svg)
[![Go Reference](https://pkg.go.dev/badge/github.com/siyanew/num2fa.svg)](https://pkg.go.dev/github.com/siyanew/num2fa)

# Num2Fa - Number to Farsi Words

This is a Golang library that helps you convert numbers to Farsi(Persian) words.

## Usage
Expand All @@ -7,11 +11,11 @@ To use the library, simply import it into your project and call the Num2fa funct
import "github.com/siyanew/num2fa"

func main() {
// Prints "سیصد هفتاد و شش"
fmt.Println(num2fa.Num2fa(376))
// Prints "سیصد هفتاد و شش"
fmt.Println(num2fa.Convert(376))

// Prints "منفی یک میلیارد و دویست و سی و چهار میلیون و پانصد و شصت و هفت هزار و هشتصد و نود"
fmt.Println(num2fa.Num2fa(-1234567890))
// Prints "منفی یک میلیارد و دویست و سی و چهار میلیون و پانصد و شصت و هفت هزار و هشتصد و نود"
fmt.Println(num2fa.Convert(-1234567890))
}
```

Expand Down
4 changes: 2 additions & 2 deletions num2fa.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package num2fa

import (
"strings"
Expand Down Expand Up @@ -101,7 +101,7 @@ func threeDigitToPersianWord(number int) string {
return strings.Join(result, " و ")
}

func Num2fa(number int) string {
func Convert(number int) string {
if number == 0 {
return "صفر"
}
Expand Down
15 changes: 6 additions & 9 deletions num2fa_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main
package num2fa_test

import "testing"
import (
"github.com/siyanew/num2fa"
"testing"
)

func TestNum2fa(t *testing.T) {
testCases := []struct {
Expand Down Expand Up @@ -35,16 +38,10 @@ func TestNum2fa(t *testing.T) {
{100000000, "صد میلیون"},
{1000000000, "یک میلیارد"},
{-1234567890, "منفی یک میلیارد و دویست و سی و چهار میلیون و پانصد و شصت و هفت هزار و هشتصد و نود"},
//{10000000000, "ده میلیارد"},
//{100000000000, "صد میلیارد"},
//{1000000000000, "یک تریلیون"},
//{10000000000000, "ده تریلیون"},
//{100000000000000, "صد تریلیون"},
//{1000000000000000, "یک کوآدریلیون"},
}

for _, tc := range testCases {
if actual := Num2fa(tc.input); actual != tc.expected {
if actual := num2fa.Convert(tc.input); actual != tc.expected {
t.Errorf("Num2fa(%d) = %s; expected %s", tc.input, actual, tc.expected)
}
}
Expand Down

0 comments on commit bdf3707

Please # to comment.