view MapTest.m @ 577:e45c9b56d50d feature/grids

Add an Empty grid class The need turned up for the flexural code when we may or may not have a grid for the open water and want to plot that solution. In case there is no open water we need an empty grid to plot the empty gridfunction against to avoid errors.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 07 Sep 2017 09:16:12 +0200
parents effd75b113ba
children a6c5e73ff44e
line wrap: on
line source

function tests = MatTest()
    tests = functiontests(localfunctions);
end

function kvp = getKeyValuePairs()
    kvp = {
        {1,3},1;
        struct(), [1; 3; 4];
        [1,2; 4 3], struct();
        'Hej', struct('lol', 6);
        0, 'Nej';
    };
end

function testSetAndGet(testCase)
    keyValuePairs = getKeyValuePairs();

    map = Map();

    % Insert
    for i = 1:length(keyValuePairs)
        map(keyValuePairs{i,1}) = keyValuePairs{i,2};
    end

    % Validate output
    for i = 1:length(keyValuePairs)
        v = map(keyValuePairs{i,1});
        testCase.verifyEqual(v, keyValuePairs{i,2});
    end
end

function map = exampleMap()
    keyValuePairs = getKeyValuePairs();

    map = Map();

    % Insert
    for i = 1:length(keyValuePairs)
        map(keyValuePairs{i,1}) = keyValuePairs{i,2};
    end
end

function testLength(testCase)
    map = Map();
    testCase.verifyEqual(map.length, 0);

    map = exampleMap();
    testCase.verifyEqual(map.length, 5)
end


function testIsKey(testCase)
    map = exampleMap();

    keyValuePairs = getKeyValuePairs();
    keys = keyValuePairs(:,1);

    for i = 1:length(keys)
        testCase.verifyTrue(map.isKey(keys{i}));
    end

    notKeys = {
        'hej',
        [],
        1,
        {2,5},
    };

    for i = 1:length(notKeys)
        testCase.verifyFalse(map.isKey(notKeys{i}));
    end
end


function testRemove(testCase)
    map = exampleMap();

    remove(map, struct());

    testCase.verifyFalse(map.isKey(struct()));
end

% function testValues(testCase)
%     keyValuePairs = getKeyValuePairs();

%     map = exampleMap();

%     testCase.verifyEqual(values(map), keyValuePairs(:,2)');
% end

% function testKeys(testCase)
%     keyValuePairs = getKeyValuePairs();

%     map = exampleMap();

%     testCase.verifyEqual(keys(map), keyValuePairs(:,1)');
% end