Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision ea44f4474e640ca632b40d75d03b57b037a4a7da authored by Konrad Werys on 18 March 2019, 12:43:10 UTC, committed by Konrad Werys on 18 March 2019, 12:43:10 UTC
unnecesary merge
2 parent s ef0fa1f + b0e72bf
  • Files
  • Changes
  • 39234d3
  • /
  • tests
  • /
  • KWUtil_test.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:ea44f4474e640ca632b40d75d03b57b037a4a7da
directory badge
swh:1:dir:dad51c9e9d3020da50c4a5a225e4af46c76c42dc
content badge
swh:1:cnt:7c4482c5c87811de4bf41d89c92b15cce624ce8f

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
KWUtil_test.cpp
/*!
 * \file KWUtil_test.cpp
 * \author Konrad Werys
 * \date 2018/10/04
 */

#include "KWUtil.h"

#include "gtest/gtest.h"

//#include <iostream>
//#include <cmath>
//#include <cerrno>
//#include <cstring>
//#include <cfenv>
//#pragma STDC FENV_ACCESS ON
//
//TEST(KWUtil, error) {
//
//    if (fpclassify(0) == FP_ZERO) {
//        std::cout << "zero" << std::endl;
//    }
//
//    try {
//        std::cout << exp(710) << std::endl;
//    } catch (...){
//        std::cout << "error" << std::endl;
//    }
//    errno = 0;
//    std::feclearexcept(FE_ALL_EXCEPT);
//    std::cout << "exp(710) = " << std::exp(710) << '\n';
//    if (errno == ERANGE)
//        std::cout << "    errno == ERANGE: " << std::strerror(errno) << '\n';
//    if (std::fetestexcept(FE_OVERFLOW))
//        std::cout << "    FE_OVERFLOW raised\n";
//
////    int a = 1;
////    int b = 0;
////    try{
////        std::cout << "1/0: " << a/b << std::endl;
////    } catch (...) {
////        std::cout << "exception" << std::endl;
////    }
//
////    //fesetenv(3);
////    errno = 0;
////    if (math_errhandling & MATH_ERREXCEPT) feclearexcept(FE_ALL_EXCEPT);
////
////    printf ("Error handling: %d",math_errhandling);
////
////    sqrt (-1);
////    if (math_errhandling & MATH_ERRNO) {
////        if (errno==EDOM) printf("errno set to EDOM\n");
////    }
////    if (math_errhandling  & MATH_ERREXCEPT) {
////        if (fetestexcept(FE_INVALID)) printf("FE_INVALID raised\n");
////    }
//
////    double d = 1.0 / 0.0;
////    switch (fpclassify(d)) {
////        case FP_INFINITE:  printf ("infinite");  break;
////        case FP_NAN:       printf ("NaN");       break;
////        case FP_ZERO:      printf ("zero");      break;
////        case FP_SUBNORMAL: printf ("subnormal"); break;
////        case FP_NORMAL:    printf ("normal");    break;
////    }
////    if (signbit(d)) printf (" negative\n");
////    else printf (" positive or unsigned\n");
//
//}

TEST(KWUtil, dicomTime2Seconds) {

    std::string dicomTimeString = "141650.92";
    double dicomTimeSeconds = 14*3600 + 16*60 + 50.92;

    double result = KWUtil::dicomTime2Seconds<double>(dicomTimeString);
    EXPECT_DOUBLE_EQ(result, dicomTimeSeconds);
}

TEST(KWUtil, calcMatrixInverse3x3) {

    double matrix[9] = {2, 2, 2, 4, 5, 4, 7, 8, 2};
    double invMatrixCorrect[9] = { 2.2, -1.2, 0.2, -2, 1, 0, 0.3, 0.2, -0.2};
    double invMatrixCalculated[9];

    EXPECT_EQ(KWUtil::calcMatrixInverse3x3(matrix, invMatrixCalculated), 0); // EXIT_SUCCESS

    EXPECT_DOUBLE_EQ(invMatrixCalculated[0], invMatrixCorrect[0]);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[1], invMatrixCorrect[1]);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[2], invMatrixCorrect[2]);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[3], invMatrixCorrect[3]);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[4], invMatrixCorrect[4]);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[5], invMatrixCorrect[5]);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[6], invMatrixCorrect[6]);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[7], invMatrixCorrect[7]);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[8], invMatrixCorrect[8]);
}

TEST(KWUtil, calcMatrixInverse3x3_detZero) {

    double matrix[9] = {2, 2, 2, 3, 3, 3, 1, 1, 1};
    double invMatrixCalculated[9];

    EXPECT_EQ(KWUtil::calcMatrixInverse3x3(matrix, invMatrixCalculated), 1); // EXIT_FAILURE

    EXPECT_DOUBLE_EQ(invMatrixCalculated[0], 0);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[1], 0);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[2], 0);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[3], 0);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[4], 0);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[5], 0);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[6], 0);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[7], 0);
    EXPECT_DOUBLE_EQ(invMatrixCalculated[8], 0);
}


The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API