-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 error on cpu and memory combination
- Loading branch information
Showing
4 changed files
with
177 additions
and
14 deletions.
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
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,65 @@ | ||
package tasks | ||
|
||
func ValidateCombinationOfCpuAndMemory(cpu uint64, memory uint64) bool { | ||
if cpu == 0 && memory == 0 { | ||
return true | ||
} | ||
|
||
if cpu == 256 { | ||
if memory >= 512 && memory <= 2048 { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
if cpu == 512 { | ||
if memory >= 1024 && memory <= 4096 { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
if cpu == 1024 { | ||
if memory >= 2048 && memory <= 8192 { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
if cpu == 2048 { | ||
if memory >= 4096 && memory <= 16384 { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
if cpu == 4096 { | ||
if memory >= 8192 && memory <= 30720 { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
if cpu == 8192 { | ||
if memory >= 16384 && memory <= 61440 { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
if cpu == 16384 { | ||
if memory >= 32768 && memory <= 122880 { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
return false | ||
} |
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,42 @@ | ||
package tasks | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestValidateCpuAndMemory(t *testing.T) { | ||
cases := []struct { | ||
cpu uint64 | ||
memory uint64 | ||
expect bool | ||
}{ | ||
{ | ||
cpu: 0, | ||
memory: 0, | ||
expect: true, | ||
}, | ||
{ | ||
cpu: 128, | ||
memory: 128, | ||
expect: false, | ||
}, | ||
{ | ||
cpu: 256, | ||
memory: 512, | ||
expect: true, | ||
}, | ||
{ | ||
cpu: 1024, | ||
memory: 2048, | ||
expect: true, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
result := ValidateCombinationOfCpuAndMemory(c.cpu, c.memory) | ||
|
||
if result != c.expect { | ||
t.Fail() | ||
} | ||
} | ||
} |