Commit 018c84f4 authored by Rennarde's avatar Rennarde
Browse files

Rework test update

parent d2574f9a
......@@ -14,5 +14,11 @@
"Gravity": false,
"GravityCenter": false,
"NumCycle": 0,
"LifeOpt": [""]
"LifeOpt": [""],
"Pictures": "",
"Scaleimg": false,
"Spawnimg" : false,
"GravityPoint": false,
"Clock" : false,
"Horlogescale" : 2
}
\ No newline at end of file
......@@ -10,14 +10,14 @@
"scaleY":1,
"SpawnX": 400,
"SpawnY": 400,
"SpawnRate": 0.00025,
"SpawnRate": 0.25,
"SpeedLimit": [0,0,0,0],
"Colors": [0,1,0,1,0,1],
"Gravity": false,
"GravityCenter": false,
"NumCycle": 300,
"Pictures": "",
"LifeOpt": ["grow","fade","Death"],
"LifeOpt": ["grow","white","fade","Death"],
"Scaleimg": false,
"Spawnimg" : false,
"GravityPoint": false,
......
......@@ -27,9 +27,9 @@ func UpdateCycle(Part Particle) (Particle) {
Part.Overflow = true
}
if config.General.LifeOpt[i] == "white" {
Part.ColorRed += (1-Part.ColorRed)*(1-(float64(Part.Life) / float64(config.General.NumCycle)))
Part.ColorBlue += (1-Part.ColorBlue)*(1-(float64(Part.Life) / float64(config.General.NumCycle)))
Part.ColorGreen += (1-Part.ColorGreen)*(1-(float64(Part.Life) / float64(config.General.NumCycle)))
Part.ColorRed = float64(config.General.NumCycle) / float64(Part.Life)
Part.ColorBlue = float64(config.General.NumCycle) / float64(Part.Life)
Part.ColorGreen = float64(config.General.NumCycle) / float64(Part.Life)
}
if config.General.LifeOpt[i] == "fade" {
Part.Opacity = (float64(Part.Life)/float64(config.General.NumCycle))
......
......@@ -2,9 +2,8 @@ package particles
import (
"testing"
"math/rand"
"time"
"project-particles/config"
"fmt"
)
func TestVitesseNull(t *testing.T){
......@@ -42,21 +41,122 @@ func Test_Netoyage(t *testing.T) {
config.General.WindowSizeY = 400
config.General.SpawnX = 200
config.General.SpawnY = 200
config.General.RandomSpawn = false
config.General.InitNumParticles = 10
config.General.SpeedLimit = []float64 {1,1,0,0}
p := GenPart()
Ptab := []Particle {p}
config.General.SpawnX = 397
p = GenPart()
Ptab = append(Ptab,p)
rand.Seed(time.Now().UnixNano())
for i:=0; i < 15; i++ {
if rand.Intn(1) == 1 {
config.General.SpawnX = 397
p = GenPart()
} else {
config.General.SpawnX = 200
p = GenPart()
Sys := NewSystem()
config.General.SpawnX = 395
for i:=0; i < 10; i++ {
Sys.Content = append(Sys.Content,GenPart())
}
for i:=0; i < 10 ; i++ {
Sys.Update()
for j:=0; j < len(Sys.Content); j++ {
if Sys.Content[j].PositionX > 401 {
t.Fail()
}
}
}
}
func Test_UpdateCycle_Life(t *testing.T) {
config.Get("../Extension/TestConfig.json")
config.General.InitNumParticles = 10
config.General.NumCycle = 5
config.General.LifeOpt = []string {""}
Sys := NewSystem()
var tmp int
for i:=0; i < 7; i++ {
for j:=0; j < len(Sys.Content); j++ {
tmp = Sys.Content[j].Life
Sys.Content[j] = UpdateCycle(Sys.Content[j])
if tmp - 1 != Sys.Content[j].Life {
t.Fail()
}
}
}
}
func Test_UpdateCycle_Death(t *testing.T) {
config.Get("../Extension/TestConfig.json")
config.General.InitNumParticles = 10
config.General.NumCycle = 5
config.General.LifeOpt = []string {"Death"}
Sys := NewSystem()
for i:=0; i < 7; i++ {
for j:=0; j < len(Sys.Content); j++ {
Sys.Content[j] = UpdateCycle(Sys.Content[j])
if Sys.Content[j].Life < 1 && Sys.Content[j].Overflow == false {
t.Fail()
}
}
}
}
func Test_UpdateCycle_White(t *testing.T) {
config.Get("../Extension/TestConfig.json")
config.General.InitNumParticles = 10
config.General.NumCycle = 5
config.General.LifeOpt = []string {"white"}
Sys := NewSystem()
for i:=0; i < 7; i++ {
for j:=0; j < len(Sys.Content); j++ {
Sys.Content[j] = UpdateCycle(Sys.Content[j])
if Sys.Content[j].ColorRed != 5 / float64(Sys.Content[j].Life) || Sys.Content[j].ColorBlue != 5 / float64(Sys.Content[j].Life) || Sys.Content[j].ColorGreen != 5 / float64(Sys.Content[j].Life) {
t.Fail()
}
}
}
}
func Test_UpdateCycle_Fade(t *testing.T) {
config.Get("../Extension/TestConfig.json")
config.General.InitNumParticles = 10
config.General.NumCycle = 5
config.General.LifeOpt = []string {"fade"}
Sys := NewSystem()
for i:=0; i < 7; i++ {
for j:=0; j < len(Sys.Content); j++ {
Sys.Content[j] = UpdateCycle(Sys.Content[j])
if Sys.Content[j].Opacity != (float64(Sys.Content[j].Life)/float64(config.General.NumCycle)) {
t.Fail()
}
}
Ptab = append(Ptab,p)
}
}
\ No newline at end of file
}
// NOT WORKING ATM
// func Test_UpdateCycle_Grow(t *testing.T) {
// config.Get("../Extension/TestConfig.json")
// config.General.InitNumParticles = 10
// config.General.NumCycle = 5
// config.General.LifeOpt = []string {"grow"}
// config.General.ScaleX = 1
// config.General.ScaleY = 1
// config.General.WindowSizeX = 400
// config.General.WindowSizeY = 400
// config.General.SpawnX = 200
// config.General.SpawnY = 200
// config.General.RandomSpawn = false
// config.General.SpeedLimit = []float64 {0,0,0,0}
// Sys := NewSystem()
// var OldPosX,OldPosY float64
// // var OldScaleX,OldScaleY float64
// for i:=0; i < 7; i++ {
// for j:=0; j < len(Sys.Content); j++ {
// OldPosX = Sys.Content[j].PositionX
// OldPosY = Sys.Content[j].PositionY
// // OldScaleX = Sys.Content[j].ScaleX
// // OldScaleY = Sys.Content[j].ScaleY
// Sys.Content[j] = UpdateCycle(Sys.Content[j])
// if OldPosX-0.0125 != Sys.Content[j].PositionX || OldPosY-0.0125 != Sys.Content[j].PositionY {
// fmt.Println(OldPosX-0.0125,Sys.Content[j].PositionX)
// t.Fail()
// }
// // if OldScaleX+0.025 != Sys.Content[j].ScaleX || OldScaleY+0.025 != Sys.Content[j].ScaleY {
// // t.Fail()
// // }
// }
// }
// }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment