Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
817725f
commit daf91dc
Showing
7 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ module.exports = { | |
"text", | ||
"time", | ||
"ytm", | ||
"memory", | ||
], | ||
}, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"strconv" | ||
|
||
mem "github.com/pbnjay/memory" | ||
) | ||
|
||
type memory struct { | ||
props *properties | ||
env environmentInfo | ||
TotalMemory uint64 | ||
FreeMemory uint64 | ||
} | ||
|
||
const ( | ||
Precision Property = "precision" | ||
) | ||
|
||
func (n *memory) enabled() bool { | ||
return true | ||
} | ||
|
||
func (n *memory) string() string { | ||
newText := strconv.FormatFloat(100.0/float64(n.TotalMemory)*float64(n.TotalMemory-n.FreeMemory), 'f', n.props.getInt(Precision, 0), 64) | ||
return newText | ||
} | ||
|
||
func (n *memory) init(props *properties, env environmentInfo) { | ||
n.props = props | ||
n.env = env | ||
n.TotalMemory = mem.TotalMemory() | ||
n.FreeMemory = mem.FreeMemory() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMemory(t *testing.T) { | ||
cases := []struct { | ||
Case string | ||
ExpectedString string | ||
Memory memory | ||
Precision int | ||
}{ | ||
{Case: "50", ExpectedString: "50", Memory: memory{FreeMemory: 50, TotalMemory: 100}}, | ||
{Case: "50.0", ExpectedString: "50.0", Memory: memory{FreeMemory: 50, TotalMemory: 100}, Precision: 1}, | ||
} | ||
|
||
for _, tc := range cases { | ||
tc.Memory.env = new(MockedEnvironment) | ||
tc.Memory.props = &properties{ | ||
values: map[Property]interface{}{ | ||
Precision: tc.Precision, | ||
}, | ||
} | ||
assert.Equal(t, tc.ExpectedString, tc.Memory.string(), tc.Case) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters