github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/consumer/entertainment/estimator_test.go (about)

     1  /*
     2   * Copyright (C) 2021 The "MysteriumNetwork/node" Authors.
     3   *
     4   * This program is free software: you can redistribute it and/or modify
     5   * it under the terms of the GNU General Public License as published by
     6   * the Free Software Foundation, either version 3 of the License, or
     7   * (at your option) any later version.
     8   *
     9   * This program is distributed in the hope that it will be useful,
    10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   * GNU General Public License for more details.
    13   *
    14   * You should have received a copy of the GNU General Public License
    15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16   */
    17  
    18  package entertainment
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  )
    25  
    26  func TestEstimator(t *testing.T) {
    27  	// given
    28  	estimator := NewEstimator(0.01, 0.0001)
    29  
    30  	// expect
    31  	assert.Equal(t, 102400.0, estimator.totalTrafficMiB(1))
    32  	assert.Equal(t, 204800.0, estimator.totalTrafficMiB(2))
    33  
    34  	assert.Equal(t, uint64(106), estimator.minutes(1, 1000))
    35  	assert.Equal(t, uint64(53), estimator.minutes(1, 2000))
    36  	assert.Equal(t, uint64(9555), estimator.minutes(1, 0.5))
    37  
    38  	// and
    39  	e := estimator.EstimatedEntertainment(5)
    40  	assert.Equal(t, uint64(536870), e.TrafficMB)
    41  	assert.Equal(t, 0.01, e.PricePerGiB)
    42  	assert.Equal(t, 0.0001, e.PricePerMin)
    43  
    44  	// can fluctuate based on constants so just assert it's set
    45  	assert.Less(t, uint64(0), e.VideoMinutes)
    46  	assert.Less(t, uint64(0), e.MusicMinutes)
    47  	assert.Less(t, uint64(0), e.BrowsingMinutes)
    48  }