Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) TestPrimeExpert

 

TestPrimeExpert is a tool to test the PrimeExpert class.

 

 

 

 

 

TestPrimeExpert downloads

 

 

 

 

 

 

Older TestPrimeExpert downloads

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ToolTestPrimeExpert.pro

 

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra

TEMPLATE = app
INCLUDEPATH += \
    ../../Classes/CppAbout \
    ../../Classes/CppPrimeExpert \
    ../../Classes/CppQtAboutDialog
SOURCES += main.cpp\
   testprimeexpertdialog.cpp \
    ../../Classes/CppAbout/about.cpp \
    ../../Classes/CppPrimeExpert/primeexpert.cpp \
    ../../Classes/CppQtAboutDialog/qtaboutdialog.cpp
HEADERS  += \
    testprimeexpertdialog.h \
    ../../Classes/CppAbout/about.h \
    ../../Classes/CppPrimeExpert/primeexpert.h \
    ../../Classes/CppQtAboutDialog/qtaboutdialog.h
FORMS += \
    testprimeexpertdialog.ui \
    ../../Classes/CppQtAboutDialog/qtaboutdialog.ui

 

 

 

 

 

main.cpp

 

//---------------------------------------------------------------------------
/*
TestPrimeExpert, tool to test the PrimeExpert class
Copyright (C) 2008-2011 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPrimeExpert.htm
//---------------------------------------------------------------------------
#include <QApplication>
#include "testprimeexpertdialog.h"
//---------------------------------------------------------------------------
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  TestPrimeExpertDialog w;
  w.show();
  return a.exec();
}
//---------------------------------------------------------------------------

 

 

 

 

 

testprimeexpertdialog.h

 

//---------------------------------------------------------------------------
/*
TestPrimeExpert, tool to test the PrimeExpert class
Copyright (C) 2008-2011 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPrimeExpert.htm
//---------------------------------------------------------------------------
#ifndef TESTPRIMEEXPERTDIALOG_H
#define TESTPRIMEEXPERTDIALOG_H
//------------------------------------------------------------
#include "primeexpert.h"
#include <QDialog>
//------------------------------------------------------------
namespace Ui {
  class TestPrimeExpertDialog;
}
//------------------------------------------------------------
class TestPrimeExpertDialog : public QDialog
{
  Q_OBJECT

public:
  explicit TestPrimeExpertDialog(QWidget *parent = 0);
  ~TestPrimeExpertDialog();
  static const std::string GetVersion();
  static const std::vector<std::string> GetVersionHistory();

protected:
  void changeEvent(QEvent *e);

private:
  Ui::TestPrimeExpertDialog *ui;
  PrimeExpert m_expert;

private slots:
    void on_button_about_clicked();
    void on_edit_value_textChanged(QString );
};
//------------------------------------------------------------
#endif // TESTPRIMEEXPERTDIALOG_H
//------------------------------------------------------------

 

 

 

 

 

testprimeexpertdialog.cpp

 

//---------------------------------------------------------------------------
/*
TestPrimeExpert, tool to test the PrimeExpert class
Copyright (C) 2008-2011 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPrimeExpert.htm
//---------------------------------------------------------------------------
#include <boost/lexical_cast.hpp>
#include <boost/timer.hpp>
//------------------------------------------------------------
#include "about.h"
#include "qtaboutdialog.h"
#include "testprimeexpertdialog.h"
#include "ui_testprimeexpertdialog.h"
//------------------------------------------------------------
TestPrimeExpertDialog::TestPrimeExpertDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TestPrimeExpertDialog)
{
  ui->setupUi(this);
  ui->edit_value->setText("2");
}
//------------------------------------------------------------
TestPrimeExpertDialog::~TestPrimeExpertDialog()
{
  delete ui;
}
//------------------------------------------------------------
void TestPrimeExpertDialog::changeEvent(QEvent *e)
{
  QDialog::changeEvent(e);
  switch (e->type()) {
  case QEvent::LanguageChange:
    ui->retranslateUi(this);
    break;
  default:
    break;
  }
}
//------------------------------------------------------------
const std::string TestPrimeExpertDialog::GetVersion()
{
  return "2.0";
}
//---------------------------------------------------------------------------
const std::vector<std::string> TestPrimeExpertDialog::GetVersionHistory()
{
  std::vector<std::string> v;
  v.push_back("2008-07-12: Version 1.0: initial version in C++ Builder");
  v.push_back("2011-02-26: Version 2.0: port to Qt Creator");
  return v;
}
//---------------------------------------------------------------------------
void TestPrimeExpertDialog::on_edit_value_textChanged(QString s)
{
  ui->text->clear();
  try
  {
    boost::lexical_cast<int>(s.toStdString());
  }
  catch (boost::bad_lexical_cast&)
  {
    ui->text->appendPlainText("NaN");
    return;
  }
  const int value = boost::lexical_cast<int>(s.toStdString());
  if (value < 2)
  {
    ui->text->appendPlainText("Not prime");
    return;
  }
  if (value == 2)
  {
    ui->text->appendPlainText("Prime");
    return;
  }
  const boost::timer t;
  const bool isPrime = m_expert.IsPrime(value);
  const double time = t.elapsed();
  const std::string text
    = std::string(isPrime ? "Prime" : "Not prime")
    + " ("
    + boost::lexical_cast<std::string>(time)
    + " sec)";
  ui->text->appendPlainText(text.c_str());
}
//------------------------------------------------------------
void TestPrimeExpertDialog::on_button_about_clicked()
{
  About about(
    "Richel Bilderbeek",
    "TestPrimeExpert",
    "Tool to test the PrimeExpert class",
    "the 26th of February 2011",
    "2008-2011",
    "http://www.richelbilderbeek.nl/ToolTestPrimeExpert.htm",
    GetVersion(),
    GetVersionHistory());
  about.AddLibrary("PrimeExpert version: " + PrimeExpert::GetVersion());
  QtAboutDialog d(about);
  d.exec();
}
//------------------------------------------------------------

 

 

 

 

 

zip.sh

 

#!/bin/sh
#zip packs all the files to port into a single .zip file,
#minicking the same folder structure
#Folder structure
# *
#   * Classes
#     * CppAbout
#     * CppPrimeExpert
#     * CppQtAboutDialog
#   * Tools
#    * ToolTestPrimeExpert
echo "Mimicking file structure"
mkdir temp_zip
mkdir temp_zip/Classes
mkdir temp_zip/Classes/CppAbout
mkdir temp_zip/Classes/CppPrimeExpert
mkdir temp_zip/Classes/CppQtAboutDialog
mkdir temp_zip/Tools
mkdir temp_zip/Tools/ToolTestPrimeExpert

echo "Copying files"
cp ../../Classes/CppAbout/*.* temp_zip/Classes/CppAbout
cp ../../Classes/CppPrimeExpert/*.* temp_zip/Classes/CppPrimeExpert
cp ../../Classes/CppQtAboutDialog/*.* temp_zip/Classes/CppQtAboutDialog
cp ../../Tools/ToolTestPrimeExpert/*.* temp_zip/Tools/ToolTestPrimeExpert

echo "Compressing files"
cd temp_zip

zip -r ToolTestPrimeExpertSource_2_0 Classes
zip -r ToolTestPrimeExpertSource_2_0 Tools

echo "Copying zipped file from temp folder to this folder"

cd ..
cp temp_zip/ToolTestPrimeExpertSource_2_0.zip ToolTestPrimeExpertSource_2_0.zip

echo "Cleaning up"
#Classes
rm temp_zip/Classes/CppAbout/*.*
rm temp_zip/Classes/CppPrimeExpert/*.*
rm temp_zip/Classes/CppQtAboutDialog/*.*
rmdir temp_zip/Classes/CppAbout
rmdir temp_zip/Classes/CppPrimeExpert
rmdir temp_zip/Classes/CppQtAboutDialog
rmdir temp_zip/Classes
#Tools
rm temp_zip/Tools/ToolTestPrimeExpert/*.*
rmdir temp_zip/Tools/ToolTestPrimeExpert
rmdir temp_zip/Tools
rm temp_zip/*.*
rmdir temp_zip
echo "Done"

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml