/* Checks for a scenario where only FIRST FIT works  
   and other policies should fail.
*/

#include <stdio.h>
#include <unistd.h>
#include "mem.h"

int main()
{
    int err, i, j;
    void *p[8];
    int sizes[8] = { 88, 488, 148, 488, 88, 1356, 388, 956};
    void **ptrs[3];
  
    printf("1\n");

    err = Mem_Init(4096, P_FIRSTFIT);
    if(err == -1)
        return -1;

    for(i=0; i<8; i++) {
        p[i] = Mem_Alloc(sizes[i]);
        if(p[i] == NULL)
             return -1;
    }
//    Mem_Dump();

    ptrs[0] = &p[2];
    ptrs[1] = &p[4];
    ptrs[2] = &p[6];

    for(i=0; i<3; i++) {
       err = Mem_Free(*ptrs[i]);
       if(err == -1)
             return -1;
    }
//    Mem_Dump();

    p[0]= Mem_Alloc(68);
    if(p[0] == NULL)
         return -1;

    p[2]= Mem_Alloc(68);
    if(p[2] == NULL)
         return -1;

    p[4]= Mem_Alloc(380);
    if(p[4] == NULL)
         return -1;

    //This should work for FIRST FIT and should not for others   
    p[6]= Mem_Alloc(88);
    if(p[6] == NULL)
         return -1;


    return 0;
}

