clear all;
close all;
clc;

tol = 1e-14;

% testcase 1
b = 2;
d = [1 0 1 0 0 1 0 0];
v = [0 0 1 0 0];
t = 1;
x = bad2dez(b,d,v,t);
if (abs(x-10.25) < tol)
    fprintf('Testcase 1: Passed.\n')
else
    fprintf(2,'Testcase 1: Failed.\n')
end

% testcase 2
b = 2;
d = [1 0 1];
v = [0 0 1];
t = -1;
x = bad2dez(b,d,v,t);
if (abs(x-0.3125) < tol)
    fprintf('Testcase 2: Passed.\n')
else
    fprintf(2,'Testcase 2: Failed.\n')
end

% testcase 3
b = 8;
d = [7 5 0];
v = [0 0 1];
t = -1;
x = bad2dez(b,d,v,t);
if (abs(x-0.119140625) < tol)
    fprintf('Testcase 3: Passed.\n')
else
    fprintf(2,'Testcase 3: Failed.\n')
end
 