Sha256: a75d6a02e2353bff6c9dca81f23ac28fef3bdd0bed6b12bb7c402232a4369e18

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'helper'
require 'claymore/gpu_hash_rate.rb'

class GPUHashRateTest < Test::Unit::TestCase
  test 'return nil when no match' do
    assert_nil service('ETH: GPU0')
    assert_nil service('GPU0 24.1 Mh/s')
    assert_nil service('SC - Total Speed: 292.684 Mh/s')
  end

  test 'extracts individual GPU hash rates when available' do
    text = 'ETH: GPU0 24.314 Mh/s, GPU1 24.01 Mh/s, GPU20 24.1 Mh/s'
    assert_equal service(text), [
      { 'asset' => 'ETH', 'gpu' => 0, 'hash_rate' => 24.314, 'type' => 'GPU_HASH_RATE' },
      { 'asset' => 'ETH', 'gpu' => 1, 'hash_rate' => 24.01, 'type' => 'GPU_HASH_RATE' },
      { 'asset' => 'ETH', 'gpu' => 20, 'hash_rate' => 24.1, 'type' => 'GPU_HASH_RATE' }
    ]
  end

  test 'extracts asset name' do
    text = 'SC: GPU0 292.862 Mh/s'
    assert_equal service(text), [
      { 'asset' => 'SC', 'gpu' => 0, 'hash_rate' => 292.862, 'type' => 'GPU_HASH_RATE' }
    ]
  end

  test 'assigns -1 hash rate value when GPU is off' do
    text = 'ETH: GPU0 29 Mh/s, GPU1 off'
    assert_equal service(text), [
      { 'asset' => 'ETH', 'gpu' => 0, 'hash_rate' => 29, 'type' => 'GPU_HASH_RATE' },
      { 'asset' => 'ETH', 'gpu' => 1, 'hash_rate' => -1.0, 'type' => 'GPU_HASH_RATE' }
    ]

    text = 'LBC: GPU0 off'
    assert_equal service(text), [
      { 'asset' => 'LBC', 'gpu' => 0, 'hash_rate' => -1.0, 'type' => 'GPU_HASH_RATE' }
    ]
  end

  def service(text)
    Claymore::GPUHashRate.call(text)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-claymore-1.0.0 test/claymore/test_gpu_hash_rate.rb