// Code your testbench here
// or browse Examples
// Code your design here
typedef enum {red,green,blue,ivory,yellow} color_e;
typedef enum {tea,milk,coffee,orangejuice,water} drink_e;
typedef enum {kools,chester,luckystrike,parliments,oldgold}smoke_e;
typedef enum {horse,fox,zebra,snails,dog} animals_e;
typedef enum {english,norwei,japan,spain,ukrain} nation_e;
typedef struct {
rand color_e color [5];
rand drink_e drink [5];
rand smoke_e smoke [5];
rand animals_e animals [5];
rand nation_e nation [5];
} house_e;
module tb;
class zebra_puzzle;
rand house_e house[5];
constraint st2 {
foreach (house[i])
house[i].nation == english <-> house[i].color == red;
}
constraint st3 {
foreach (house[i])
house[i].nation == spain <-> house[i].animals == dog;
}
constraint st4 {
foreach (house[i])
house[i].nation == green <-> house[i].drink == coffee;
}
constraint st5 {
foreach (house[i])
house[i].nation == ukrain <-> house[i].drink == tea;
}
constraint st6 {
foreach (house[i])
if (i<4)
house[i].color == ivory -> house[i+1].color == green;
}
constraint st7 {
foreach (house[i])
// if (i<4)
house[i].smoke == oldgold -> house[i].animals == snails;
}
constraint st8 {
foreach (house[i])
house[i].smoke == kools <-> house[i].color == yellow;
}
constraint st9 {
foreach (house[i])
house[2].drink == milk;
}
constraint st10 {
foreach (house[i])
house[0].nation == norwei;
}
constraint st11 {
house[0].smoke==chester -> house[1].animals == fox;
house[4].smoke==chester -> house[3].animals == fox;
foreach (house[i])
if (i>0 && i<4)
house[i].smoke == chester -> (house[i+1].animals == fox) || (house[i-1].animals == fox);
}
constraint st12 {
house[0].smoke==kools -> house[1].animals == horse;
house[4].smoke==kools -> house[3].animals == horse;
foreach (house[i])
if (i>0 && i<4)
house[i].smoke == kools -> (house[i+1].animals == horse) || (house[i-1].animals == horse);
}
constraint st13 {
foreach (house[i])
house[i].smoke == luckystrike -> house[i].drink ==orangejuice;
}
constraint st14 {
foreach (house[i])
house[i].nation == japan -> house[i].smoke==parliments;
}
constraint st15 {
// foreach (house[i])
house[0].nation == norwei -> house[1].color==blue;
}
function void post_randomize();
print();
endfunction
//----------------------------------------------------------------------
function void print();
foreach (house[i]) begin
$display("House number %0d:", i);
$display(" color = %s", house[i].color.name());
$display(" nationality = %s", house[i].nation.name());
$display(" pet = %s", house[i].animals.name());
$display(" drink = %s", house[i].drink.name());
$display(" cigarettes = %s", house[i].smoke.name());
$display("\n");
end
endfunction
endclass
initial begin
zebra_puzzle z1 = new();
if (!z1.randomize());
$error("Could not solve the puzzle");
$finish;
end
endmodule
Error-[PMCOFSAT] Called on fixed size array type
testbench.sv, 141
"house[i].nation.name"
Predefined method 'name' cannot be called on a fixed size array.
Please refer to SV LRM (IEEE Std 1800-2009) chapter 7.4 for detailed
information.[\systemverilog]