Changeset b46f285 in sasview for src/sas/qtgui/UnitTesting


Ignore:
Timestamp:
Jan 9, 2017 9:49:16 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
87cc73a
Parents:
a66ff280
Message:

Unit tests for linear fit

Location:
src/sas/qtgui/UnitTesting
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/UnitTesting/GuiUtilsTest.py

    r27313b7 rb46f285  
    346346        self.assertFalse(os.path.isfile(file_name)) 
    347347 
     348    def testXYTransform(self): 
     349        """ Assure the unit/legend transformation is correct""" 
     350        data = Data1D(x=[1.0, 2.0, 3.0], y=[10.0, 11.0, 12.0], 
     351                      dx=[0.1, 0.2, 0.3], dy=[0.1, 0.2, 0.3]) 
     352 
     353        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="x", yLabel="y") 
     354        self.assertEqual(xLabel, "()") 
     355        self.assertEqual(xscale, "linear") 
     356        self.assertEqual(yscale, "linear") 
     357 
     358        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="x^(2)", yLabel="1/y") 
     359        self.assertEqual(xLabel, "^{2}(()^{2})") 
     360        self.assertEqual(yLabel, "1/(()^{-1})") 
     361        self.assertEqual(xscale, "linear") 
     362        self.assertEqual(yscale, "linear") 
     363 
     364        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="x^(4)", yLabel="ln(y)") 
     365        self.assertEqual(xLabel, "^{4}(()^{4})") 
     366        self.assertEqual(yLabel, "\\ln{()}()") 
     367        self.assertEqual(xscale, "linear") 
     368        self.assertEqual(yscale, "linear") 
     369 
     370        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="ln(x)", yLabel="y^(2)") 
     371        self.assertEqual(xLabel, "\\ln{()}()") 
     372        self.assertEqual(yLabel, "^{2}(()^{2})") 
     373        self.assertEqual(xscale, "linear") 
     374        self.assertEqual(yscale, "linear") 
     375 
     376        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="log10(x)", yLabel="y*x^(2)") 
     377        self.assertEqual(xLabel, "()") 
     378        self.assertEqual(yLabel, " \\ \\ ^{2}(()^{2})") 
     379        self.assertEqual(xscale, "log") 
     380        self.assertEqual(yscale, "linear") 
     381 
     382        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="log10(x^(4))", yLabel="y*x^(4)") 
     383        self.assertEqual(xLabel, "^{4}(()^{4})") 
     384        self.assertEqual(yLabel, " \\ \\ ^{4}(()^{16})") 
     385        self.assertEqual(xscale, "log") 
     386        self.assertEqual(yscale, "linear") 
     387 
     388        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="x", yLabel="1/sqrt(y)") 
     389        self.assertEqual(yLabel, "1/\\sqrt{}(()^{-0.5})") 
     390        self.assertEqual(yscale, "linear") 
     391 
     392        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="x", yLabel="log10(y)") 
     393        self.assertEqual(yLabel, "()") 
     394        self.assertEqual(yscale, "log") 
     395 
     396        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="x", yLabel="ln(y*x)") 
     397        self.assertEqual(yLabel, "\\ln{( \\ \\ )}()") 
     398        self.assertEqual(yscale, "linear") 
     399 
     400        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="x", yLabel="ln(y*x^(2))") 
     401        self.assertEqual(yLabel, "\\ln ( \\ \\ ^{2})(()^{2})") 
     402        self.assertEqual(yscale, "linear") 
     403 
     404        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="x", yLabel="ln(y*x^(4))") 
     405        self.assertEqual(yLabel, "\\ln ( \\ \\ ^{4})(()^{4})") 
     406        self.assertEqual(yscale, "linear") 
     407 
     408        xLabel, yLabel, xscale, yscale = xyTransform(data, xLabel="x", yLabel="log10(y*x^(4))") 
     409        self.assertEqual(yLabel, " \\ \\ ^{4}(()^{4})") 
     410        self.assertEqual(yscale, "log") 
     411 
    348412class FormulaValidatorTest(unittest.TestCase): 
    349413    """ Test the formula validator """ 
  • src/sas/qtgui/UnitTesting/Plotter2DTest.py

    r27313b7 rb46f285  
    7474        """ Test the right click menu """ 
    7575        self.plotter.data = self.data 
     76        self.plotter.createContextMenuQuick() 
    7677        actions = self.plotter.contextMenu.actions() 
    7778        self.assertEqual(len(actions), 7) 
  • src/sas/qtgui/UnitTesting/PlotterTest.py

    raadf0af1 rb46f285  
    6969        self.assertTrue(FigureCanvas.draw.called) 
    7070 
    71     def testContextMenuQuickPlot(self): 
     71    def testCreateContextMenuQuick(self): 
    7272        """ Test the right click menu """ 
    7373        self.plotter.createContextMenuQuick() 
     
    112112        self.assertTrue(self.plotter.properties.exec_.called) 
    113113 
    114     def testXYTransform(self): 
    115         """ Assure the unit/legend transformation is correct""" 
    116         self.plotter.plot(self.data) 
    117  
    118         self.plotter.xyTransform(xLabel="x", yLabel="y") 
     114    def testXyTransform(self): 
     115        """ Tests the XY transformation and new chart update """ 
     116        self.plotter.plot(self.data) 
     117 
     118        # Transform the points 
     119        self.plotter.xyTransform(xLabel="x", yLabel="log10(y)") 
     120 
     121        # Assure new plot has correct labels 
    119122        self.assertEqual(self.plotter.ax.get_xlabel(), "$()$") 
    120123        self.assertEqual(self.plotter.ax.get_ylabel(), "$()$") 
    121  
    122         self.plotter.xyTransform(xLabel="x^(2)", yLabel="1/y") 
    123         self.assertEqual(self.plotter.ax.get_xlabel(), "$^{2}(()^{2})$") 
    124         self.assertEqual(self.plotter.ax.get_ylabel(), "$1/(()^{-1})$") 
    125  
    126         self.plotter.xyTransform(xLabel="x^(4)", yLabel="ln(y)") 
    127         self.assertEqual(self.plotter.ax.get_xlabel(), "$^{4}(()^{4})$") 
    128         self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln{()}()$") 
    129  
    130         self.plotter.xyTransform(xLabel="ln(x)", yLabel="y^(2)") 
    131         self.assertEqual(self.plotter.ax.get_xlabel(), "$\\ln{()}()$") 
    132         self.assertEqual(self.plotter.ax.get_ylabel(), "$^{2}(()^{2})$") 
    133  
    134         self.plotter.xyTransform(xLabel="log10(x)", yLabel="y*x^(2)") 
    135         self.assertEqual(self.plotter.ax.get_xlabel(), "$()$") 
    136         self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ \\ ^{2}(()^{2})$") 
    137  
    138         self.plotter.xyTransform(xLabel="log10(x^(4))", yLabel="y*x^(4)") 
    139         self.assertEqual(self.plotter.ax.get_xlabel(), "$^{4}(()^{4})$") 
    140         self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ \\ ^{4}(()^{16})$") 
    141  
    142         self.plotter.xyTransform(xLabel="x", yLabel="1/sqrt(y)") 
    143         self.assertEqual(self.plotter.ax.get_ylabel(), "$1/\\sqrt{}(()^{-0.5})$") 
    144  
    145         self.plotter.xyTransform(xLabel="x", yLabel="log10(y)") 
    146         self.assertEqual(self.plotter.ax.get_ylabel(), "$()$") 
    147  
    148         self.plotter.xyTransform(xLabel="x", yLabel="ln(y*x)") 
    149         self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln{( \\ \\ )}()$") 
    150  
    151         self.plotter.xyTransform(xLabel="x", yLabel="ln(y*x^(2))") 
    152         self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln ( \\ \\ ^{2})(()^{2})$") 
    153  
    154         self.plotter.xyTransform(xLabel="x", yLabel="ln(y*x^(4))") 
    155         self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln ( \\ \\ ^{4})(()^{4})$") 
    156  
    157         self.plotter.xyTransform(xLabel="x", yLabel="log10(y*x^(4))") 
    158         self.assertEqual(self.plotter.ax.get_ylabel(), "$ \\ \\ ^{4}(()^{4})$") 
     124        # ... and scale 
     125        self.assertEqual(self.plotter.xscale, "linear") 
     126        self.assertEqual(self.plotter.yscale, "log") 
     127        # See that just one plot is present 
     128        self.assertEqual(len(self.plotter.plot_dict), 1) 
     129        self.assertEqual(len(self.plotter.ax.collections), 1) 
    159130 
    160131    def testAddText(self): 
     
    250221        self.assertNotEqual(self.plotter.ax.get_ylim(), new_y) 
    251222 
     223    def testOnLinearFit(self): 
     224        """ Checks the response to LinearFit call """ 
     225        pass 
     226 
     227    def testOnRemovePlot(self): 
     228        """ Assure plots get removed when requested """ 
     229        pass 
     230 
     231    def testRemovePlot(self): 
     232        """ Test plot removal """ 
     233        pass 
     234 
     235    def testOnToggleHideError(self): 
     236        """ Test the error bar toggle on plots """ 
     237        pass 
     238 
     239    def testOnFitDisplay(self): 
     240        """ Test the fit line display on the chart """ 
     241        pass 
     242 
    252243if __name__ == "__main__": 
    253244    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.