Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.88 KB | None | 0 0
  1. /*                S P H E R E . C P P
  2. * BRL-CAD
  3. *
  4. * Copyright (c) 2014 United States Government as represented by
  5. * the U.S. Army Research Laboratory.
  6. *
  7. * This file is in the public domain.
  8. *
  9. *                        DISCLAIMER OF LIABILITY
  10. *
  11. * THIS FILE WAS CAREFULLY TESTED BY THE AUTHOR AND IS MADE AVAILABLE TO YOU
  12. * FREE-OF-CHARGE IN A HIGH-GRADE ACTUAL STATUS. REFERENCE IS MADE HEREWITH TO
  13. * THE FACT THAT IT IS NOT POSSIBLE TO DEVELOP SOFTWARE PROGRAMS SO THAT THEY
  14. * ARE ERROR-FREE FOR ALL APPLICATION CONDITIONS. AS THE FILE IS LICENSED FREE
  15. * OF CHARGE THERE IS NO WARRANTY FOR IT, INSOFAR AS SUCH WARRANTY IS NOT A
  16. * MANDATORY REQUIREMENT OF THE APPLICABLE LAW, SUCH AS IN CASE OF WILFUL ACTS.
  17. * IN ADDITION THERE IS NO LIABILITY ALSO INSOFAR AS SUCH LIABILITY IS NOT A
  18. * MANDATORY REQUIREMENT OF THE APPLICABLE LAW, SUCH AS IN CASE OF WILFUL ACTS.
  19. *
  20. * YOU DECLARE YOU ARE IN AGREEMENT WITH THE USE OF THIS FILE UNDER THE
  21. * ABOVE-LISTED USAGE CONDITIONS AND THE EXCLUSION OF A GUARANTEE AND OF
  22. * LIABILITY. SHOULD INDIVIDUAL PROVISIONS IN THESE CONDITIONS BE IN FULL OR IN
  23. * PART VOID, INVALID OR CONTESTABLE, THE VALIDITY OF ALL OTHER PROVISIONS OR
  24. * AGREEMENTS ARE UNAFFECTED BY THIS. FURTHER THE PARTIES UNDERTAKE AT THIS
  25. * JUNCTURE TO AGREE A LEGALLY VALID REPLACEMENT CLAUSE WHICH MOST CLOSELY
  26. * APPROXIMATES THE ECONOMIC OBJECTIVES.
  27. */
  28. /** @file Sphere.cpp
  29. *  This file is a coreInterface test for Sphere.cpp.
  30. */
  31. #include <iostream>
  32. #include <brlcad/Sphere.h>
  33. using namespace BRLCAD;
  34. int testSphereCenter(BRLCAD::sphere sph, double expectedX, double expectedY, double expectedZ) /* Tests Sphere's Center function */
  35. {
  36.     if(sph.Center().coordinates[0]==expectedX && sph.center().coordinates[1]==expectedY && sph.center().coordinates[2]==expectedZ) return 0;       
  37.     return 1;
  38. }
  39. int testSphereClassName(BRLCAD::sphere sph) /* Tests Sphere's ClassName function */
  40. {
  41.     if(sph.ClassName()=="Sphere") return 0;
  42.     return 1;
  43. }
  44. int testSphereType(BRLCAD::sphere sph) /* Tests Sphere's Type function */
  45. {
  46.     if(sph.Type()=="Sphere") return 0;
  47.     return 1;
  48. }
  49. int testSphereIsValid(BRLCAD::sphere sph) /* Tests Sphere's SphereIsValid function */
  50. {
  51.     if(sph.IsValid()==true) return 0;
  52.     return 1;
  53. }
  54. int testSphereRadius(BRLCAD::sphere sph,double expectedRadius) /* Tests Sphere's SphereRadius function */
  55. {
  56.     if(sph.Radius()==expectedRadius) return 0;
  57.     return 1;
  58. }
  59. int testSphereClone(BRLCAD::Sphere sph) /* Tests Sphere's Clone function */
  60. {
  61.     BRLCAD::Sphere sph2;
  62.     sph2=sph.clone();
  63.         if(sph2.Center().coordinates[0]==sph.Center().coordinates[0] && sph2.Center().coordinates[1]==sph.Center().coordinates[1] && sph2.Center().coordinates[2]==sph.Center().coordinates[2] && sph2.Radius()==sph.Radius() ) return 0; /* Checks if the two Spheres are equal */
  64.     return 1;
  65. }
  66. int testSphereSet() /* Tests Sphere's Set function */
  67. {
  68.     BRLCAD::Sphere sph2;
  69.     sph2.set(Vector3D(1.0,1.0,1.0),3.0);
  70.         if(sph2.Center().coordinates[0]==1.0 && sph2.Center().coordinates[1]==1.0 && sph2.Center().coordinates[2]==1.0 && sph2.Radius()==3.0) return 0; /* Checks if  Set worked properly */
  71.     return 1;
  72. }
  73. void test_sphere(BRLCAD::Database& database)
  74. {  
  75.     BRLCAD::sphere sph; /* Initialize a Sphere to test on */
  76.     sph.SetCenter(Vector3D(1.0,1.0,1.0));
  77.     sph.SetRadius(30.0);
  78.         if( testSphereIsValid(sph)==0 )
  79.             if( testSphereType(sph)==0 )
  80.                 if( testSphereClassName(sph)==0 )
  81.                     if( testSphereCenter(sph, 1.0, 1.0, 1.0)==0 )
  82.                         if( testSphereRadius(sph, 30.0)==0 )
  83.                             if( testSphereClone(sph)==0 )
  84.                                 if( testSphereSet()==0 )
  85.                                     database.add(sph);
  86.                                 else std::cout<<"Failed test at : Set()";
  87.                             else std::cout<<"Failed test at : Clone()";
  88.                         else std::cout<<"Failed test at : Radius()";
  89.                     else std::cout<<"Failed test at : Center()";
  90.                 else std::cout<<"Failed test at : ClassName()";
  91.             else std::cout<<"Failed test at : Type()";
  92.         else std::cout<<"Failed test at : IsValid()";
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement