// ============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
//
//  This file is distributed under the same license as the Scilab package.
// ============================================================================
//
// <-- ENGLISH IMPOSED -->
//
// <-- Short Description -->
// Test MEAI_IdealCommutSwitch

[a, coselicaMacrosPath] = libraryinfo(whereis(getCoselicaVersion));

try
    ilib_verbose(0);
    assert_checktrue(importXcosDiagram(coselicaMacrosPath + "../../tests/unit_tests/Electrical/Ideal/MEAI_IdealCommutSwitch.zcos"));
    xcos_simulate(scs_m, 4);
    
    I1 = res.values(:,1);
    I2 = res.values(:,2);
    cmd = res.values(:,3);
    V=5*ones(I1);
    R1 = 2;
    R2 = 3;
    Ron = 0.00001;
    Goff = 0.00001;

    ind = find(cmd>0);
    assert_checkalmostequal(I2(ind), V(ind)/(R2+Ron));
    assert_checktrue(abs(I1(ind) - V(ind)*Goff) < 1d-9);
    ind = find(cmd==0);
    assert_checkalmostequal(I1(ind), V(ind)/(R1+Ron));
    assert_checktrue(abs(I2(ind) - V(ind)*Goff) < 1d-8);

catch
   disp(lasterror())
   assert_checktrue(%f);
end
