How to use test_sample method in Slash

Best Python code snippet using slash

test.py

Source:test.py Github

copy

Full Screen

1import unittest2import numpy as np3from decimal import *4class LinearRegressionTestCase(unittest.TestCase):5 """Test for linear regression project"""6 def test_calc_Norm(self):7 test_sample=[1,2,3,4,5]8 self.assertEqual(Decimal(calc_Norm(test_sample,p=0,infty=False)),5.0,'L0 Wrong answer')9 self.assertEqual(calc_Norm(test_sample,p=1,infty=False),15.0,'L1 Wrong answer')10 self.assertEqual(calc_Norm(test_sample,p=2,infty=False),7.416198487095663,'L2 Wrong answer')11 self.assertEqual(calc_Norm(test_sample,p=2,infty=True),5.0,'L_max Wrong answer')12 13 test_sample=np.array([1.2])14 self.assertEqual(Decimal(calc_Norm(test_sample,p=0,infty=False)),1.0,'L0 Wrong answer')15 self.assertEqual(calc_Norm(test_sample,p=1,infty=False),1.2,'L1 Wrong answer')16 self.assertEqual(calc_Norm(test_sample,p=2,infty=False),1.2,'L2 Wrong answer')17 self.assertEqual(calc_Norm(test_sample,p=2,infty=True),1.2,'L_max Wrong answer') 18 19 def test_calc_Frobenius_Norm(self):20 test_sample=[[1,2,3],[4,5,6]]21 self.assertEqual(Decimal(calc_Frobenius_Norm(test_sample)),9.539392014169456,'Wrong answer')22 23 24 def test_calc_Condition_Number(self):25 test_sample=[[1,2],[2,4.0001]]26 self.assertEqual(Decimal(calc_Condition_Number(test_sample)),250008.00010058272,'Wrong answer')27 test_sample=[[1,2],[3,4]]28 self.assertEqual(Decimal(calc_Condition_Number(test_sample)),14.999999999999998,'Wrong answer')29 def test_calc_svd(self):30 test_sample =[[1,2],[3,4]]31 result = (np.array([[-0.40455358, -0.9145143 ],32 [-0.9145143 , 0.40455358]]),33 np.array([5.4649857 , 0.36596619]),34 np.array([[-0.57604844, -0.81741556],35 [ 0.81741556, -0.57604844]]))36 self.assertEqual(calc_svd(test_sample)[0].any()==result[0].any(),True,'Wrong answer U')37 self.assertEqual(calc_svd(test_sample)[1].any()==result[1].any(),True,'Wrong answer D')38 self.assertEqual(calc_svd(test_sample)[2].any()==result[2].any(),True,'Wrong answer VT') 39 40 def test_calc_svd_decompostion(self):41 test_sample =[[1,2,3,4,5,6,7,8],42 [2,3,4,5,6,7,8,9],43 [3,4,5,6,7,8,9,10],44 [4,5,6,7,8,9,10,11],45 [5,6,7,8,9,10,11,12]]46 result = np.array([[-14.13331129, -2.06143446],47 [-16.81265405, -1.15527645],48 [-19.49199682, -0.24911844],49 [-22.17133959, 0.65703957],50 [-24.85068235, 1.56319758]])51 52 self.assertEqual(calc_svd_decompostion(test_sample).any()==result.any(),True,'Wrong answer') 53 54 def test_calc_svd_reconsitution(self):55 test_sample =[[1,2,3,4,5,6,7,8],56 [2,3,4,5,6,7,8,9],57 [3,4,5,6,7,8,9,10],58 [4,5,6,7,8,9,10,11],59 [5,6,7,8,9,10,11,12]]60 result = np.array([[ 2.28811868, 2.98679854, 3.68547839, 4.38415824, 5.0828381 ,61 5.78151795, 6.4801978 , 7.17887766],62 [ 2.72189206, 3.55302515, 4.38415824, 5.21529133, 6.04642442,63 6.87755751, 7.7086906 , 8.53982369],64 [ 3.15566545, 4.11925177, 5.0828381 , 6.04642442, 7.01001075,65 7.97359707, 8.9371834 , 9.90076972],66 [ 3.58943883, 4.68547839, 5.78151795, 6.87755751, 7.97359707,67 9.06963663, 10.16567619, 11.26171575],68 [ 4.02321221, 5.25170501, 6.4801978 , 7.7086906 , 8.9371834 ,69 10.16567619, 11.39416899, 12.62266179]])70 71 self.assertEqual(calc_svd_reconsitution(test_sample,topk=1).any()==result.any(),True,'Wrong answer') 72 73 74if __name__ == '__main__':...

Full Screen

Full Screen

test_convert_records_to_fo.py

Source:test_convert_records_to_fo.py Github

copy

Full Screen

1import imp2from venv import create3import pytest4from PIL import Image5from fiftyone import list_datasets, load_dataset, Detection, Sample, Dataset6from icevision import tfms7from icevision import data8from icevision.data import Prediction9from icevision.data.convert_records_to_fo import (10 _convert_bbox_to_fo_bbox,11 record_to_fo_detections,12)13# Test subject14from icevision.data import (15 convert_record_to_fo_sample,16 convert_prediction_to_fo_sample,17 create_fo_dataset,18)19from tests.conftest import object_detection_record20# Fixtures21@pytest.fixture(scope="function")22def cleanup_fo_dataset():23 dataset_test_names = ["_iv_test", "_iv_test_1"]24 yield25 for dataset_name in dataset_test_names:26 if dataset_name in list_datasets():27 ds = load_dataset(dataset_name)28 ds.delete()29 del ds30# Test from low to high abstraction31def test_record_to_fo_detections(object_detection_record):32 detections = record_to_fo_detections(33 object_detection_record, lambda bbox: _convert_bbox_to_fo_bbox(bbox, 500, 500)34 )35 for fo_bbox in detections:36 assert isinstance(fo_bbox, Detection)37def test_convert_record_to_fo_sample(object_detection_record):38 # Test create new sample39 test_sample = convert_record_to_fo_sample(40 object_detection_record, "test", None, False, None, lambda x: x41 )42 assert isinstance(test_sample, Sample)43 assert hasattr(test_sample, "test")44 assert len(test_sample["test"]) > 045 # Test add to existing sample and autosave46 sample = Sample(object_detection_record.common.filepath)47 test_sample = convert_record_to_fo_sample(48 object_detection_record, "test", sample, False, None, lambda x: x49 )50 assert isinstance(test_sample, Sample)51 assert hasattr(test_sample, "test")52 assert len(test_sample["test"]) > 053 # Test iv postprocess bbox54 test_tfms = [55 tfms.A.Adapter([*tfms.A.resize_and_pad([1000, 1000]), tfms.A.Normalize()])56 ]57 test_sample = convert_record_to_fo_sample(58 object_detection_record, "test", None, False, test_tfms, None59 )60 assert isinstance(test_sample, Sample)61 assert hasattr(test_sample, "test")62 assert len(test_sample["test"]) > 063def test_convert_prediction_to_fo_sample(object_detection_record):64 # Create Prediction65 object_detection_record.original_img_size = [1000, 1000]66 object_detection_prediction = Prediction(67 object_detection_record, object_detection_record68 )69 test_sample = convert_prediction_to_fo_sample(70 object_detection_prediction, undo_bbox_tfms_fn=lambda x: x71 )72 del (73 object_detection_record.original_img_size74 ) # Cleanup record, that has scope session75 assert isinstance(test_sample, Sample)76 assert hasattr(test_sample, "ground_truth")77 assert len(test_sample["ground_truth"]) > 078 assert hasattr(test_sample, "prediction")79 assert len(test_sample["prediction"]) > 080def test_create_fo_dataset(object_detection_record, cleanup_fo_dataset):81 # Create Prediction82 object_detection_record.original_img_size = [1000, 1000]83 object_detection_prediction = Prediction(84 object_detection_record, object_detection_record85 )86 # Test for record and with existing dataset87 dataset = Dataset("_iv_test")88 dataset = create_fo_dataset(89 [object_detection_prediction], dataset_name="_iv_test", exist_ok=True90 )91 del (92 object_detection_record.original_img_size93 ) # Cleanup record, that has scope session94 assert isinstance(dataset, Dataset)95 assert len(list(dataset.iter_samples())) > 096 # Test for prediction and create new dataset97 dataset = create_fo_dataset([object_detection_record], "_iv_test_1")98 assert isinstance(dataset, Dataset)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful