Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mxssl/topn
Go implementation of topn app that finds top N numbers in a file
https://github.com/mxssl/topn
go golang test-task topn
Last synced: about 2 months ago
JSON representation
Go implementation of topn app that finds top N numbers in a file
- Host: GitHub
- URL: https://github.com/mxssl/topn
- Owner: mxssl
- Created: 2020-02-28T00:28:01.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-28T01:06:34.000Z (almost 5 years ago)
- Last Synced: 2024-11-14T01:33:14.621Z (about 2 months ago)
- Topics: go, golang, test-task, topn
- Language: Go
- Homepage:
- Size: 88.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-golang-repositories - topn
README
# topn
topn finds top N numbers in a file
## Task
Write a program, topN, that given an arbitrarily large file and a number, N, containing individual numbers on each line (e.g. 200Gb file), will output the largest N numbers, highest first.
## Install
- [Install go](https://golang.org/dl/)
- `make build`## Usage
### Generate file
`topn generate --lines N --name filename` - generate `file` with `N` lines of random numbers.
### Find the top N of largest numbers
`topn run --file filename --top N`
### Example
- Generate file `numbers.txt` with `1000` lines of random numbers
```sh
./topn generate --name numbers.txt --lines 1000
File numbers.txt with 1000 lines of random numbers was successfully generated!
```- Find top 5 largest numbers in file `numbers.txt`
```sh
./topn run --file numbers.txt --top 5
[9219151525891662339 9215619702456294450 9207997407084704522 9207450753580197605 9173624551887931713]
```## Test
```sh
go test -cover -v ./...
? github.com/mxssl/topn [no test files]
=== RUN TestCase1
expected: [100 90 80 70 60]
output: [100 90 80 70 60]
--- PASS: TestCase1 (0.00s)
PASS
coverage: 42.3% of statements
ok github.com/mxssl/topn/cmd 0.260s coverage: 42.3% of statements
```