/**
 * This sketch was written in order to test the List and Queue datastructures used in my project
 * This test was aimed toward spotting memory leaks
 * Anatole SCHRAMM-HENRY 08/05/2019
 */
 
#include "D:/Users/Think/Desktop/Mes documents/Programmation/Arduino/ESP8266_swiss_army_board/src/app/List.h"
#include "D:/Users/Think/Desktop/Mes documents/Programmation/Arduino/ESP8266_swiss_army_board/src/app/Queue.h"

uint32_t timer(0);

List<String> strList;
Queue<String> strQueue;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  timer = millis();
}

void loop() {
  // put your main code here, to run repeatedly:
  strList.addFirst(String("Vive l'esp"));
  strList.addLast(strList.removeFirstRef());
  strList.addFirst(strList.removeLastRef());
  strList.addLast(String("Vive l'esp"));
  
  
  strQueue.add(String("Meme pas vrai"));
  delete strQueue.removeRef();
  strQueue.add(String("Meme pas vrai"));
  strQueue.remove();
  if(millis() - timer >= 1000)
  {
    debugInfo();
    timer = millis();
  }

  if(strList.count() > 20)
  {
    //Serial.println("Cleared");
    strList.clear();
  }
  strList.removeFirst();

}


void debugInfo()
{
  uint32_t freeMem;
  uint16_t biggestContigMemBlock;
  uint8_t frag;
  ESP.getHeapStats(&freeMem, &biggestContigMemBlock, &frag);
  Serial.print("Free MEM : ");Serial.println(freeMem);
  Serial.print("Heap Frag : ");Serial.println(frag);
}
