/******************************** /
\ testlru2.c                      \
/                                 /
\ Single-threaded LRU correctness \
/ test, testing the LRU_Access    /
\ function.                       \
/*********************************/

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

int main() {
  LRU_Init(1000);
  int i;
  
  // Fill up the LRU
  for(i = 1; i <= 1000; i++) {
    if (LRU_Insert(i)) {
      printf("Test failed.\n");
      return 0;
    }
  }
  
  // Access every item in the LRU
  // This operation will reverse the order of the queue.
  for(i = 1000; i > 0; i--) {
    if (LRU_Access(i)) {
      printf("Test failed.\n");
      return 0;
    }
  }

  // Make sure the LRU_Access function return -1 when a number
  // not in the LRU is passed in.
  if (LRU_Access(9999) != -1) {
    printf("Test failed.\n");
    return 0;
  }
  
  // Make sure the queue really did reverse its order
  // in the previous for loop
  for(i = 1; i <=1000; i++) {
    int x = LRU_Insert(i + 1000);
    if (x != 1000 - i + 1) {
      printf("Test failed.\n");
      return 0;
    } 
  }
  return 0;
}
