/******************************** /
\ testlru1.c                      \
/                                 /
\ Single-threaded LRU correctness \
/ test, testing the LRU_Insert    /
\ function.                       \
/*********************************/

#include "lru.h"
#include <stdlib.h>
#include <stdio.h>

int main() {
  LRU_Init(1000);
  srand(59);
  int i;
  
  // Fill up the LRU
  for(i = 1; i <= 1000; i++) {
    if (LRU_Insert(i)) {
      printf("fail during insertion of %d\n", i);
      printf("Test failed.\n");
      return 0;
    }
  }
 
//	LL_Dump();

  // Try inserting random numbers.
  // Should return -1 every time because the LRU already has all numbers
  // between 1 and 1000 (inclusive).
  for(i = 1; i < 1000000; i++) {
    if (LRU_Insert(rand() % 1000 + 1) != -1) {
      LL_Dump();
      printf("test failed because it returned\n");
      printf("Test failed.\n");
      return 0;
    }
  }
  
  // Make sure the LRU returns values in the same order they were added.
  for(i = 0; i < 1000; i++) {
    int x = LRU_Insert(i + 2000);
    if (x != i + 1) {
      printf("Test failed.\n");
      return 0;
    } 
  }
  return 0;
}
